From 2a31202a8c6fcf535abfdcea8d2cc8c7fe18792c Mon Sep 17 00:00:00 2001 From: Barba Date: Wed, 10 Jul 2024 18:45:45 -0300 Subject: [PATCH 01/17] Update Test Suit --- packages/foundry/coverage.txt | 103 +------ .../TestnetFork/ProtocolTestnet.t.sol | 261 ++++++++++-------- .../UnitTests/ConceroChildPool.t.sol | 5 + .../Pos-Upgradeable/UnitTests/Infra.t.sol | 4 +- 4 files changed, 153 insertions(+), 220 deletions(-) diff --git a/packages/foundry/coverage.txt b/packages/foundry/coverage.txt index d1254a6ce..ebd5be9e0 100644 --- a/packages/foundry/coverage.txt +++ b/packages/foundry/coverage.txt @@ -3,102 +3,10 @@ Uncovered for ../hardhat/contracts/ConceroAutomation.sol: Uncovered for ../hardhat/contracts/ConceroBridge.sol: Uncovered for ../hardhat/contracts/ConceroChildPool.sol: -- Function "onlyMessenger" (location: source ID 3, line 90, chars 4388-4518, hits: 0) -- Line (location: source ID 3, line 91, chars 4423-4456, hits: 0) -- Statement (location: source ID 3, line 91, chars 4423-4456, hits: 0) -- Statement (location: source ID 3, line 91, chars 4423-4447, hits: 0) -- Branch (branch: 1, path: 0) (location: source ID 3, line 91, chars 4419-4506, hits: 0) -- Branch (branch: 1, path: 1) (location: source ID 3, line 91, chars 4419-4506, hits: 0) -- Statement (location: source ID 3, line 91, chars 4458-4506, hits: 0) - Branch (branch: 3, path: 1) (location: source ID 3, line 106, chars 4910-5025, hits: 0) - Statement (location: source ID 3, line 106, chars 4976-5025, hits: 0) -- Function "" (location: source ID 3, line 115, chars 5314-5857, hits: 0) -- Line (location: source ID 3, line 125, chars 5577-5610, hits: 0) -- Statement (location: source ID 3, line 125, chars 5577-5610, hits: 0) -- Line (location: source ID 3, line 126, chars 5616-5642, hits: 0) -- Statement (location: source ID 3, line 126, chars 5616-5642, hits: 0) -- Line (location: source ID 3, line 127, chars 5648-5687, hits: 0) -- Statement (location: source ID 3, line 127, chars 5648-5687, hits: 0) -- Line (location: source ID 3, line 128, chars 5693-5715, hits: 0) -- Statement (location: source ID 3, line 128, chars 5693-5715, hits: 0) -- Line (location: source ID 3, line 129, chars 5721-5774, hits: 0) -- Statement (location: source ID 3, line 129, chars 5721-5774, hits: 0) -- Line (location: source ID 3, line 130, chars 5780-5830, hits: 0) -- Statement (location: source ID 3, line 130, chars 5780-5830, hits: 0) -- Line (location: source ID 3, line 131, chars 5836-5852, hits: 0) -- Statement (location: source ID 3, line 131, chars 5836-5852, hits: 0) -- Function "ccipSendToPool" (location: source ID 3, line 144, chars 6288-7756, hits: 0) -- Line (location: source ID 3, line 145, chars 6433-6474, hits: 0) -- Statement (location: source ID 3, line 145, chars 6433-6474, hits: 0) -- Statement (location: source ID 3, line 145, chars 6443-6474, hits: 0) -- Branch (branch: 4, path: 0) (location: source ID 3, line 145, chars 6429-6521, hits: 0) -- Branch (branch: 4, path: 1) (location: source ID 3, line 145, chars 6429-6521, hits: 0) -- Statement (location: source ID 3, line 145, chars 6476-6521, hits: 0) -- Line (location: source ID 3, line 147, chars 6528-6604, hits: 0) -- Statement (location: source ID 3, line 147, chars 6528-6604, hits: 0) -- Statement (location: source ID 3, line 147, chars 6574-6604, hits: 0) -- Line (location: source ID 3, line 149, chars 6611-6718, hits: 0) -- Statement (location: source ID 3, line 149, chars 6611-6718, hits: 0) -- Statement (location: source ID 3, line 149, chars 6654-6718, hits: 0) -- Line (location: source ID 3, line 151, chars 6725-6754, hits: 0) -- Statement (location: source ID 3, line 151, chars 6725-6754, hits: 0) -- Line (location: source ID 3, line 153, chars 6761-7189, hits: 0) -- Statement (location: source ID 3, line 153, chars 6761-7189, hits: 0) -- Statement (location: source ID 3, line 153, chars 6807-7189, hits: 0) -- Line (location: source ID 3, line 161, chars 7196-7288, hits: 0) -- Statement (location: source ID 3, line 161, chars 7196-7288, hits: 0) -- Statement (location: source ID 3, line 161, chars 7211-7288, hits: 0) -- Line (location: source ID 3, line 163, chars 7299-7342, hits: 0) -- Statement (location: source ID 3, line 163, chars 7299-7342, hits: 0) -- Statement (location: source ID 3, line 163, chars 7306-7342, hits: 0) -- Branch (branch: 5, path: 0) (location: source ID 3, line 163, chars 7295-7432, hits: 0) -- Branch (branch: 5, path: 1) (location: source ID 3, line 163, chars 7295-7432, hits: 0) -- Statement (location: source ID 3, line 163, chars 7344-7432, hits: 0) -- Line (location: source ID 3, line 165, chars 7439-7476, hits: 0) -- Statement (location: source ID 3, line 165, chars 7439-7476, hits: 0) -- Line (location: source ID 3, line 166, chars 7482-7521, hits: 0) -- Statement (location: source ID 3, line 166, chars 7482-7521, hits: 0) -- Line (location: source ID 3, line 168, chars 7528-7653, hits: 0) -- Statement (location: source ID 3, line 168, chars 7528-7653, hits: 0) -- Line (location: source ID 3, line 170, chars 7660-7751, hits: 0) -- Statement (location: source ID 3, line 170, chars 7660-7751, hits: 0) -- Branch (branch: 7, path: 1) (location: source ID 3, line 183, chars 8343-8443, hits: 0) -- Branch (branch: 10, path: 1) (location: source ID 3, line 228, chars 10373-10989, hits: 0) -- Branch (branch: 11, path: 1) (location: source ID 3, line 231, chars 10526-10851, hits: 0) -- Line (location: source ID 3, line 236, chars 10929-10974, hits: 0) -- Statement (location: source ID 3, line 236, chars 10929-10974, hits: 0) -- Function "isMessengers" (location: source ID 3, line 257, chars 11494-12042, hits: 0) -- Line (location: source ID 3, line 258, chars 11583-11629, hits: 0) -- Statement (location: source ID 3, line 258, chars 11583-11629, hits: 0) -- Statement (location: source ID 3, line 258, chars 11613-11629, hits: 0) -- Line (location: source ID 3, line 259, chars 11670-11728, hits: 0) -- Statement (location: source ID 3, line 259, chars 11670-11728, hits: 0) -- Line (location: source ID 3, line 260, chars 11734-11792, hits: 0) -- Statement (location: source ID 3, line 260, chars 11734-11792, hits: 0) -- Line (location: source ID 3, line 261, chars 11798-11824, hits: 0) -- Statement (location: source ID 3, line 261, chars 11798-11824, hits: 0) -- Line (location: source ID 3, line 262, chars 11830-11856, hits: 0) -- Statement (location: source ID 3, line 262, chars 11830-11856, hits: 0) -- Line (location: source ID 3, line 264, chars 11868-11877, hits: 0) -- Statement (location: source ID 3, line 264, chars 11868-11877, hits: 0) -- Statement (location: source ID 3, line 264, chars 11879-11900, hits: 0) -- Line (location: source ID 3, line 265, chars 11916-11943, hits: 0) -- Statement (location: source ID 3, line 265, chars 11916-11943, hits: 0) -- Branch (branch: 12, path: 0) (location: source ID 3, line 265, chars 11912-11975, hits: 0) -- Branch (branch: 12, path: 1) (location: source ID 3, line 265, chars 11912-11975, hits: 0) -- Line (location: source ID 3, line 266, chars 11955-11966, hits: 0) -- Statement (location: source ID 3, line 266, chars 11955-11966, hits: 0) -- Line (location: source ID 3, line 269, chars 12002-12005, hits: 0) -- Statement (location: source ID 3, line 269, chars 12002-12005, hits: 0) -- Line (location: source ID 3, line 272, chars 12025-12037, hits: 0) -- Statement (location: source ID 3, line 272, chars 12025-12037, hits: 0) Uncovered for ../hardhat/contracts/DexSwap.sol: -- Function "" (location: source ID 7, line 66, chars 3089-3179, hits: 0) -- Line (location: source ID 7, line 67, chars 3138-3154, hits: 0) -- Statement (location: source ID 7, line 67, chars 3138-3154, hits: 0) -- Line (location: source ID 7, line 68, chars 3160-3174, hits: 0) -- Statement (location: source ID 7, line 68, chars 3160-3174, hits: 0) - Branch (branch: 1, path: 1) (location: source ID 7, line 81, chars 3713-3913, hits: 0) - Statement (location: source ID 7, line 82, chars 3824-3874, hits: 0) - Branch (branch: 2, path: 1) (location: source ID 7, line 82, chars 3771-3904, hits: 0) @@ -108,15 +16,8 @@ Uncovered for ../hardhat/contracts/DexSwap.sol: - Statement (location: source ID 7, line 88, chars 4108-4131, hits: 0) - Statement (location: source ID 7, line 88, chars 4113-4131, hits: 0) - Statement (location: source ID 7, line 88, chars 4149-4162, hits: 0) -- Statement (location: source ID 7, line 214, chars 9921-9951, hits: 0) -- Branch (branch: 26, path: 1) (location: source ID 7, line 214, chars 9883-10477, hits: 0) -- Line (location: source ID 7, line 229, chars 10491-10870, hits: 0) -- Statement (location: source ID 7, line 229, chars 10491-10870, hits: 0) -- Statement (location: source ID 7, line 229, chars 10539-10870, hits: 0) -- Line (location: source ID 7, line 240, chars 10879-10965, hits: 0) -- Statement (location: source ID 7, line 240, chars 10879-10965, hits: 0) -- Line (location: source ID 7, line 242, chars 10974-11022, hits: 0) -- Statement (location: source ID 7, line 242, chars 10974-11022, hits: 0) + + - Statement (location: source ID 7, line 287, chars 13003-13033, hits: 0) - Branch (branch: 33, path: 1) (location: source ID 7, line 287, chars 12965-13428, hits: 0) - Line (location: source ID 7, line 299, chars 13442-13693, hits: 0) diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index 73fa26d22..b74cea68b 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -759,127 +759,154 @@ contract ProtocolTestnet is Test { event ParentPool_MessageSent(bytes32, uint64, address, address, uint256); event ParentPool_WithdrawRequest(address,address,uint256); event ParentPool_Withdrawn(address,address,uint256); - // function test_LiquidityProvidersDepositAndOpenARequest() public setters { - // vm.selectFork(baseTestFork); + function test_LiquidityProvidersDepositAndOpenARequest() public setters { + vm.selectFork(baseTestFork); - // uint256 lpBalance = IERC20(ccipBnM).balanceOf(LP); - // uint256 depositLowAmount = 10*10**6; - - // //======= LP Deposits Low Amount of USDC on the Main Pool to revert on Min Amount - // vm.startPrank(LP); - // IERC20(ccipBnM).approve(address(wMaster), depositLowAmount); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); - // wMaster.depositLiquidity(depositLowAmount); - // vm.stopPrank(); - - // //======= Increase the CAP - // vm.expectEmit(); - // vm.prank(Tester); - // emit ParentPool_MasterPoolCapUpdated(50*10**6); - // wMaster.setPoolCap(50*10**6); - - // //======= LP Deposits enough to go through, but revert on max Cap - // uint256 depositEnoughAmount = 100*10**6; - - // vm.startPrank(LP); - // IERC20(ccipBnM).approve(address(wMaster), depositEnoughAmount); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_MaxCapReached.selector, 50*10**6)); - // wMaster.depositLiquidity(depositEnoughAmount); - // vm.stopPrank(); - - // //======= Increase the CAP - // vm.expectEmit(); - // vm.prank(Tester); - // emit ParentPool_MasterPoolCapUpdated(1000*10**6); - // wMaster.setPoolCap(1000*10**6); - - // vm.startPrank(LP); - // IERC20(ccipBnM).approve(address(wMaster), depositEnoughAmount); - // wMaster.depositLiquidity(depositEnoughAmount); - // ccipLocalSimulatorFork.switchChainAndRouteMessage(arbitrumTestFork); - // vm.stopPrank(); + uint256 lpBalance = IERC20(ccipBnM).balanceOf(LP); + uint256 depositLowAmount = 10*10**6; - // //======= Switch to Base - // vm.selectFork(baseTestFork); + //======= LP Deposits Low Amount of USDC on the Main Pool to revert on Min Amount + vm.startPrank(LP); + IERC20(ccipBnM).approve(address(wMaster), depositLowAmount); + vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); + wMaster.depositLiquidity(depositLowAmount); + vm.stopPrank(); - // //======= Check LP balance - // assertEq(IERC20(ccipBnM).balanceOf(LP), lpBalance - depositEnoughAmount); - - // //======= We check the pool balance; - // //Here, the LP Fees will be compounding directly for the LP address - // uint256 poolBalance = IERC20(ccipBnM).balanceOf(address(wMaster)); - // assertEq(poolBalance, depositEnoughAmount/2); - - // uint256 lpTokenUserBalance = lp.balanceOf(LP); - // // assertEq(lpTokenUserBalance, (depositEnoughAmount * 10**18) / 10**6); - - // //======= Revert on amount bigger than balance - // vm.startPrank(LP); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); - // wMaster.startWithdrawal(lpTokenUserBalance + 10); - // vm.stopPrank(); - - // //======= Request Withdraw without any accrued fee - // vm.startPrank(LP); - // vm.expectEmit(); - // emit ParentPool_WithdrawRequest(LP, ccipBnM, block.timestamp + 597_600); - // wMaster.startWithdrawal(lpTokenUserBalance); - // vm.stopPrank(); - - // //======= Revert on amount bigger than balance - // vm.startPrank(LP); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_ActiveRequestNotFulfilledYet.selector)); - // wMaster.startWithdrawal(lpTokenUserBalance); - // vm.stopPrank(); - - // //======= No operations are made. Advance time - // vm.warp(7 days); - - // //======= Revert Because money not arrived yet - // vm.startPrank(LP); - // lp.approve(address(wMaster), lpTokenUserBalance); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountNotAvailableYet.selector, 50*10**6)); - // wMaster.completeWithdrawal(); - // vm.stopPrank(); - - // //======= Switch to Arbitrum - // vm.selectFork(arbitrumTestFork); - - // //======= Calls ChildPool to send the money - // vm.prank(Messenger); - // wChild.ccipSendToPool(LP, depositEnoughAmount/2); - // ccipLocalSimulatorFork.switchChainAndRouteMessage(baseTestFork); - - // //======= Revert because balance was used. - // vm.prank(address(wMaster)); - // IERC20(ccipBnM).transfer(User, 10*10**6); - - // vm.startPrank(LP); - // lp.approve(address(wMaster), lpTokenUserBalance); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); - // wMaster.completeWithdrawal(); - // vm.stopPrank(); - - // vm.prank(address(User)); - // IERC20(ccipBnM).transfer(address(wMaster), 10*10**6); - - // vm.startPrank(LP); - // lp.approve(address(wMaster), lpTokenUserBalance); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_CallerIsNotTheProxy.selector, address(pool))); - // pool.completeWithdrawal(); - // vm.stopPrank(); - - // //======= Withdraw after the lock period and cross-chain transference - // vm.startPrank(LP); - // lp.approve(address(wMaster), lpTokenUserBalance); - // wMaster.completeWithdrawal(); - // vm.stopPrank(); - - // // //======= Check LP balance - // assertEq(IERC20(ccipBnM).balanceOf(LP), lpBalance); - // } + //======= Increase the CAP + vm.expectEmit(); + vm.prank(Tester); + emit ParentPool_MasterPoolCapUpdated(50*10**6); + wMaster.setPoolCap(50*10**6); + + //======= LP Deposits enough to go through, but revert on max Cap + uint256 depositEnoughAmount = 100*10**6; + + vm.startPrank(LP); + IERC20(ccipBnM).approve(address(wMaster), depositEnoughAmount); + vm.expectRevert(abi.encodeWithSelector(ParentPool_MaxCapReached.selector, 50*10**6)); + wMaster.depositLiquidity(depositEnoughAmount); + vm.stopPrank(); + + //======= Increase the CAP + vm.expectEmit(); + vm.prank(Tester); + emit ParentPool_MasterPoolCapUpdated(1000*10**6); + wMaster.setPoolCap(1000*10**6); + + vm.startPrank(LP); + IERC20(ccipBnM).approve(address(wMaster), depositEnoughAmount); + wMaster.depositLiquidity(depositEnoughAmount); + ccipLocalSimulatorFork.switchChainAndRouteMessage(arbitrumTestFork); + vm.stopPrank(); + + //======= Switch to Base + vm.selectFork(baseTestFork); + + //======= Check LP balance + assertEq(IERC20(ccipBnM).balanceOf(LP), lpBalance - depositEnoughAmount); + + //======= We check the pool balance; + //Here, the LP Fees will be compounding directly for the LP address + uint256 poolBalance = IERC20(ccipBnM).balanceOf(address(wMaster)); + assertEq(poolBalance, depositEnoughAmount/2); + + uint256 lpTokenUserBalance = lp.balanceOf(LP); + // assertEq(lpTokenUserBalance, (depositEnoughAmount * 10**18) / 10**6); + + //======= Revert on amount bigger than balance + vm.startPrank(LP); + vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); + wMaster.startWithdrawal(lpTokenUserBalance + 10); + vm.stopPrank(); + + //======= Request Withdraw without any accrued fee + vm.startPrank(LP); + vm.expectEmit(); + emit ParentPool_WithdrawRequest(LP, ccipBnM, block.timestamp + 597_600); + wMaster.startWithdrawal(lpTokenUserBalance); + vm.stopPrank(); + + //======= Revert on amount bigger than balance + vm.startPrank(LP); + vm.expectRevert(abi.encodeWithSelector(ParentPool_ActiveRequestNotFulfilledYet.selector)); + wMaster.startWithdrawal(lpTokenUserBalance); + vm.stopPrank(); + + //======= No operations are made. Advance time + vm.warp(7 days); + + //======= Revert Because money not arrived yet + vm.startPrank(LP); + lp.approve(address(wMaster), lpTokenUserBalance); + vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountNotAvailableYet.selector, 50*10**6)); + wMaster.completeWithdrawal(); + vm.stopPrank(); + + //======= Switch to Arbitrum + vm.selectFork(arbitrumTestFork); + + //======= Calls ChildPool to send the money + vm.prank(Messenger); + wChild.ccipSendToPool(LP, depositEnoughAmount/2); + ccipLocalSimulatorFork.switchChainAndRouteMessage(baseTestFork); + + //======= Revert because balance was used. + vm.prank(address(wMaster)); + IERC20(ccipBnM).transfer(User, 10*10**6); + + vm.startPrank(LP); + lp.approve(address(wMaster), lpTokenUserBalance); + vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); + wMaster.completeWithdrawal(); + vm.stopPrank(); + + vm.prank(address(User)); + IERC20(ccipBnM).transfer(address(wMaster), 10*10**6); + + vm.startPrank(LP); + lp.approve(address(wMaster), lpTokenUserBalance); + vm.expectRevert(abi.encodeWithSelector(ParentPool_CallerIsNotTheProxy.selector, address(pool))); + pool.completeWithdrawal(); + vm.stopPrank(); + + //======= Withdraw after the lock period and cross-chain transference + vm.startPrank(LP); + lp.approve(address(wMaster), lpTokenUserBalance); + wMaster.completeWithdrawal(); + vm.stopPrank(); + + // //======= Check LP balance + assertEq(IERC20(ccipBnM).balanceOf(LP), lpBalance); + } + + error ConceroChildPool_InsufficientBalance(); + error ConceroChildPool_NotEnoughLinkBalance(uint256, uint256); + function test_ccipSendToPool() public { + vm.prank(Messenger); + vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_InsufficientBalance.selector)); + wChild.ccipSendToPool(Tester, 10*10**6); + + vm.prank(0xd5CCdabF11E3De8d2F64022e232aC18001B8acAC); + ERC20Mock(ccipBnMArb).mint(address(wChild), 1000 * 10**6); + + vm.prank(Messenger); + vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_NotEnoughLinkBalance.selector, 0, 7043276117429745)); + wChild.ccipSendToPool(Tester, 10*10**6); + + vm.prank(0x4281eCF07378Ee595C564a59048801330f3084eE); + LinkToken(linkArb).transfer(address(wChild), 10*10**18); + + vm.prank(Messenger); + wChild.ccipSendToPool(Tester, 10*10**6); + } + + function test_orchestratorLoanRevertBecauseOfAmount() public setters { + vm.prank(address(proxyDst)); + vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_InsufficientBalance.selector)); + wChild.orchestratorLoan(address(aUSDC), 10 * 10**18, Tester); + } - //Callback isn't performed on forked environment + // Callback isn't performed on forked environment // function test_PoolFees() public setters { // vm.selectFork(baseTestFork); // uint256 lpBnMBalance = 1000*10**6; diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol index 44efaa28f..63c703514 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol @@ -158,4 +158,9 @@ contract ConceroChildPoolTest is Test { childPool.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(Orchestrator)); } + error ConceroChildPool_NotMessenger(address); + function test_onlyMessengerCanCall() public { + vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_NotMessenger.selector, address(this))); + wChild.ccipSendToPool(Tester, 1000*10**6); + } } diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol index 07c4d6b52..9125b7bb3 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol @@ -275,8 +275,8 @@ contract Infra is Test { wMaster = ParentPool(payable(address(masterProxy))); //====== Update the MINTER on the LP Token - // vm.prank(Tester); - // lp.grantRole(keccak256("MINTER_ROLE"), address(wMaster)); + vm.prank(Tester); + lp.grantRole(keccak256("MINTER_ROLE"), address(wMaster)); } } From d3e4718d708eb63206f84b45d037f20f28b2e021 Mon Sep 17 00:00:00 2001 From: Barba Date: Thu, 11 Jul 2024 14:20:09 -0300 Subject: [PATCH 02/17] Update Pool Interface. Add new Check. Remove deadcode. --- .../TestnetFork/ProtocolTestnet.t.sol | 86 ++++++++++--------- .../UnitTests/ConceroAutomation.t.sol | 2 +- .../hardhat/contracts/ConceroAutomation.sol | 4 +- .../hardhat/contracts/ConceroChildPool.sol | 4 +- .../hardhat/contracts/ConceroFunctions.sol | 76 ++++++++-------- packages/hardhat/contracts/DexSwap.sol | 15 +--- .../hardhat/contracts/Interfaces/IDexSwap.sol | 2 - .../Interfaces/{IParentPool.sol => IPool.sol} | 8 +- packages/hardhat/contracts/LPToken.sol | 8 +- .../contracts/Libraries/ParentStorage.sol | 8 +- .../hardhat/contracts/Libraries/Storage.sol | 5 -- .../contracts/Libraries/StorageSetters.sol | 28 +++--- packages/hardhat/contracts/Orchestrator.sol | 37 ++++---- packages/hardhat/contracts/ParentPool.sol | 44 +++++----- .../contracts/Proxy/ChildPoolProxy.sol | 1 - .../hardhat/contracts/Proxy/InfraProxy.sol | 1 - .../contracts/Proxy/ParentPoolProxy.sol | 1 - 17 files changed, 148 insertions(+), 182 deletions(-) rename packages/hardhat/contracts/Interfaces/{IParentPool.sol => IPool.sol} (89%) diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index b74cea68b..2b8ce213c 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -22,7 +22,7 @@ import {ChildPoolProxy} from "contracts/Proxy/ChildPoolProxy.sol"; import {IDexSwap} from "contracts/Interfaces/IDexSwap.sol"; import {IStorage} from "contracts/Interfaces/IStorage.sol"; import {IConcero, IDexSwap} from "contracts/Interfaces/IConcero.sol"; -import {IParentPool} from "contracts/Interfaces/IParentPool.sol"; +import {IPool} from "contracts/Interfaces/IPool.sol"; //Protocol Storage import {Storage} from "contracts/Libraries/Storage.sol"; @@ -247,6 +247,7 @@ contract ProtocolTestnet is Test { address(masterProxy), address(proxy) ); + //====== Deploy a new Orch that will e set as implementation to the proxy. orch = orchDeployBase.run( address(functionsRouterBase), @@ -759,6 +760,7 @@ contract ProtocolTestnet is Test { event ParentPool_MessageSent(bytes32, uint64, address, address, uint256); event ParentPool_WithdrawRequest(address,address,uint256); event ParentPool_Withdrawn(address,address,uint256); + ///CCIP Local doesn't allow USDC transfer in forked environment. We use ccip-BnM here. But it breaks when querying balances. function test_LiquidityProvidersDepositAndOpenARequest() public setters { vm.selectFork(baseTestFork); @@ -827,60 +829,62 @@ contract ProtocolTestnet is Test { vm.stopPrank(); //======= Revert on amount bigger than balance - vm.startPrank(LP); - vm.expectRevert(abi.encodeWithSelector(ParentPool_ActiveRequestNotFulfilledYet.selector)); - wMaster.startWithdrawal(lpTokenUserBalance); - vm.stopPrank(); + // vm.startPrank(LP); + // vm.expectRevert(abi.encodeWithSelector(ParentPool_ActiveRequestNotFulfilledYet.selector)); + // wMaster.startWithdrawal(lpTokenUserBalance); + // vm.stopPrank(); - //======= No operations are made. Advance time - vm.warp(7 days); + // //======= No operations are made. Advance time + // vm.warp(7 days); - //======= Revert Because money not arrived yet - vm.startPrank(LP); - lp.approve(address(wMaster), lpTokenUserBalance); - vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountNotAvailableYet.selector, 50*10**6)); - wMaster.completeWithdrawal(); - vm.stopPrank(); + // //======= Revert Because money not arrived yet + // vm.startPrank(LP); + // lp.approve(address(wMaster), lpTokenUserBalance); + // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountNotAvailableYet.selector, 50*10**6)); + // wMaster.completeWithdrawal(); + // vm.stopPrank(); - //======= Switch to Arbitrum - vm.selectFork(arbitrumTestFork); + // //======= Switch to Arbitrum + // vm.selectFork(arbitrumTestFork); - //======= Calls ChildPool to send the money - vm.prank(Messenger); - wChild.ccipSendToPool(LP, depositEnoughAmount/2); - ccipLocalSimulatorFork.switchChainAndRouteMessage(baseTestFork); + // //======= Calls ChildPool to send the money + // vm.prank(Messenger); + // wChild.ccipSendToPool(LP, depositEnoughAmount/2); + // ccipLocalSimulatorFork.switchChainAndRouteMessage(baseTestFork); - //======= Revert because balance was used. - vm.prank(address(wMaster)); - IERC20(ccipBnM).transfer(User, 10*10**6); + // //======= Revert because balance was used. + // vm.prank(address(wMaster)); + // IERC20(ccipBnM).transfer(User, 10*10**6); - vm.startPrank(LP); - lp.approve(address(wMaster), lpTokenUserBalance); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); - wMaster.completeWithdrawal(); - vm.stopPrank(); + // vm.startPrank(LP); + // lp.approve(address(wMaster), lpTokenUserBalance); + // vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); + // wMaster.completeWithdrawal(); + // vm.stopPrank(); - vm.prank(address(User)); - IERC20(ccipBnM).transfer(address(wMaster), 10*10**6); + // vm.prank(address(User)); + // IERC20(ccipBnM).transfer(address(wMaster), 10*10**6); - vm.startPrank(LP); - lp.approve(address(wMaster), lpTokenUserBalance); - vm.expectRevert(abi.encodeWithSelector(ParentPool_CallerIsNotTheProxy.selector, address(pool))); - pool.completeWithdrawal(); - vm.stopPrank(); + // vm.startPrank(LP); + // lp.approve(address(wMaster), lpTokenUserBalance); + // vm.expectRevert(abi.encodeWithSelector(ParentPool_CallerIsNotTheProxy.selector, address(pool))); + // pool.completeWithdrawal(); + // vm.stopPrank(); - //======= Withdraw after the lock period and cross-chain transference - vm.startPrank(LP); - lp.approve(address(wMaster), lpTokenUserBalance); - wMaster.completeWithdrawal(); - vm.stopPrank(); + // //======= Withdraw after the lock period and cross-chain transference + // vm.startPrank(LP); + // lp.approve(address(wMaster), lpTokenUserBalance); + // wMaster.completeWithdrawal(); + // vm.stopPrank(); - // //======= Check LP balance - assertEq(IERC20(ccipBnM).balanceOf(LP), lpBalance); + // // //======= Check LP balance + // assertEq(IERC20(ccipBnM).balanceOf(LP), lpBalance); } error ConceroChildPool_InsufficientBalance(); error ConceroChildPool_NotEnoughLinkBalance(uint256, uint256); + //It will fail because the amount of link charged will vary according to network stuff + //It's reverting as expect, but the revert account for the exact amount, function test_ccipSendToPool() public { vm.prank(Messenger); vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_InsufficientBalance.selector)); diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroAutomation.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroAutomation.t.sol index 334174b66..3dbe52bc9 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroAutomation.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroAutomation.t.sol @@ -7,7 +7,7 @@ import {AutomationDeploy} from "../../../script/AutomationDeploy.s.sol"; import {ConceroAutomation} from "contracts/ConceroAutomation.sol"; -import {IParentPool} from "contracts/Interfaces/IParentPool.sol"; +import {IPool} from "contracts/Interfaces/IPool.sol"; import {USDC} from "../../Mocks/USDC.sol"; diff --git a/packages/hardhat/contracts/ConceroAutomation.sol b/packages/hardhat/contracts/ConceroAutomation.sol index c154b4351..568a78a69 100644 --- a/packages/hardhat/contracts/ConceroAutomation.sol +++ b/packages/hardhat/contracts/ConceroAutomation.sol @@ -7,7 +7,7 @@ import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/autom import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/FunctionsClient.sol"; import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/libraries/FunctionsRequest.sol"; -import {IParentPool} from "./Interfaces/IParentPool.sol"; +import {IPool} from "./Interfaces/IPool.sol"; ///@notice error emitted when the caller is not the owner. error ConceroAutomation_CallerNotAllowed(address caller); @@ -186,7 +186,7 @@ contract ConceroAutomation is AutomationCompatibleInterface, FunctionsClient, Ow for (uint256 i; i < requestsNumber; ++i) { address liquidityProvider = s_pendingWithdrawRequestsCLA[i]; - IParentPool.WithdrawRequests memory pendingRequest = IParentPool(i_masterPoolProxy).getPendingWithdrawRequest(liquidityProvider); + IPool.WithdrawRequests memory pendingRequest = IPool(i_masterPoolProxy).getPendingWithdrawRequest(liquidityProvider); if (s_withdrawTriggered[liquidityProvider] == false && block.timestamp > pendingRequest.deadline) { _performData = abi.encode(liquidityProvider, pendingRequest.amountToRequest); diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index 20ad12687..c91cd2c70 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -88,7 +88,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @notice modifier to check if the caller is the an approved messenger */ modifier onlyMessenger() { - if (isMessengers(msg.sender) == false) revert ConceroChildPool_NotMessenger(msg.sender); + if (isMessenger(msg.sender) == false) revert ConceroChildPool_NotMessenger(msg.sender); _; } @@ -254,7 +254,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @notice Function to check if a caller address is an allowed messenger * @param _messenger the address of the caller */ - function isMessengers(address _messenger) internal pure returns (bool isMessenger) { + function isMessenger(address _messenger) internal pure returns (bool isMessenger) { address[] memory messengers = new address[](4); //Number of messengers. To define. messengers[0] = 0x11111003F38DfB073C6FeE2F5B35A0e57dAc4715; messengers[1] = 0x05CF0be5cAE993b4d7B70D691e063f1E0abeD267; diff --git a/packages/hardhat/contracts/ConceroFunctions.sol b/packages/hardhat/contracts/ConceroFunctions.sol index e00008582..44827d881 100644 --- a/packages/hardhat/contracts/ConceroFunctions.sol +++ b/packages/hardhat/contracts/ConceroFunctions.sol @@ -6,7 +6,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/FunctionsClient.sol"; import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/libraries/FunctionsRequest.sol"; import {Storage} from "./Libraries/Storage.sol"; -import {IParentPool} from "./Interfaces/IParentPool.sol"; +import {IPool} from "./Interfaces/IPool.sol"; import {IDexSwap} from "./Interfaces/IDexSwap.sol"; import {ConceroCommon} from "./ConceroCommon.sol"; @@ -16,7 +16,7 @@ import {ConceroCommon} from "./ConceroCommon.sol"; ///@notice error emitted when a TX was already added error TXAlreadyExists(bytes32 txHash, bool isConfirmed); ///@notice error emitted when a unexpected ID is added -error UnexpectedRequestID(bytes32); +error UnexpectedRequestID(bytes32 requestId); ///@notice error emitted when a transaction does not exist error TxDoesNotExist(); ///@notice error emitted when a transaction was already confirmed @@ -25,15 +25,7 @@ error TxAlreadyConfirmed(); error AddressNotSet(); ///@notice error emitted when an arbitrary address calls fulfillRequestWrapper error ConceroFunctions_ItsNotOrchestrator(address caller); -///@notice error emitted when a non-messenger address calls -error ConceroFunctions_NotMessenger(address); -///@notice error emitted when the chosen token is not allowed -error ConceroFunctions_TokenTypeOutOfBounds(); -///@notice error emitted when the chain index is incorrect -error ConceroFunctions_ChainIndexOutOfBounds(); -///@notice -error ConceroFunctions_PayloadNotAllowed(); - +///@notice error emitted when the delegatecall to DexSwap fails error TXReleasedFailed(bytes error); // todo: TXReleasE contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { @@ -46,11 +38,11 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { /////////////////////////////////////////////////////////// //////////////////////// VARIABLES //////////////////////// /////////////////////////////////////////////////////////// - ///@notice + ///@notice constant variable to store CLF callback gas limit uint32 public constant CL_FUNCTIONS_CALLBACK_GAS_LIMIT = 300_000; - ///@notice + ///@notice constant variable to store the fixed CLF gas overheard uint256 public constant CL_FUNCTIONS_GAS_OVERHEAD = 185_000; - ///@notice + ///@notice constant variable to help check for CLF response uint8 private constant CL_SRC_RESPONSE_LENGTH = 192; ///@notice JS Code for Chainlink Functions string private constant CL_JS_CODE = @@ -81,6 +73,7 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { event UnconfirmedTXSent(bytes32 indexed ccipMessageId, address sender, address recipient, uint256 amount, CCIPToken token, uint64 dstChainSelector); ///@notice emitted when a Unconfirmed TX is added by a cross-chain TX event UnconfirmedTXAdded(bytes32 indexed ccipMessageId, address sender, address recipient, uint256 amount, CCIPToken token, uint64 srcChainSelector); + ///@notice emitted when _handleDstFunctionsResponse finalize the process of transferring users token after cross-chain tx. event TXReleased(bytes32 indexed ccipMessageId, address indexed sender, address indexed recipient, address token, uint256 amount); ///@notice emitted when on destination when a TX is validated. event TXConfirmed(bytes32 indexed ccipMessageId, address indexed sender, address indexed recipient, uint256 amount, CCIPToken token); @@ -88,6 +81,7 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { event FunctionsRequestError(bytes32 indexed ccipMessageId, bytes32 requestId, uint8 requestType); ///@notice emitted when the concero pool address is updated event ConceroPoolAddressUpdated(address previousAddress, address pool); + constructor( FunctionsVariables memory _variables, uint64 _chainSelector, @@ -108,12 +102,6 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { /////////////////////////////////////////////////////////////// ///////////////////////////Functions/////////////////////////// /////////////////////////////////////////////////////////////// - - function getDstTotalFeeInUsdc(uint256 amount) public pure returns (uint256) { - return amount / 1000; - //@audit we can have loss of precision here? - } - function addUnconfirmedTX( bytes32 ccipMessageId, address sender, @@ -152,6 +140,16 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { emit UnconfirmedTXAdded(ccipMessageId, sender, recipient, amount, token, srcChainSelector); } + function fulfillRequestWrapper(bytes32 requestId, bytes memory response, bytes memory err) external { + if (address(this) != i_proxy) revert ConceroFunctions_ItsNotOrchestrator(address(this)); + + fulfillRequest(requestId, response, err); + } + + //////////////////////// + ///INTERNAL FUNCTIONS/// + //////////////////////// + /** * @notice Function to send a Request to Chainlink Functions * @param args the arguments for the request as bytes array @@ -165,16 +163,6 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { return _sendRequest(req.encodeCBOR(), i_subscriptionId, CL_FUNCTIONS_CALLBACK_GAS_LIMIT, i_donId); } - function fulfillRequestWrapper(bytes32 requestId, bytes memory response, bytes memory err) external { - if (address(this) != i_proxy) revert ConceroFunctions_ItsNotOrchestrator(address(this)); - - fulfillRequest(requestId, response, err); - } - - //////////////////////// - ///INTERNAL FUNCTIONS/// - //////////////////////// - function fulfillRequest(bytes32 requestId, bytes memory response, bytes memory err) internal override { Request storage request = s_requests[requestId]; @@ -239,14 +227,6 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { emit UnconfirmedTXSent(ccipMessageId, sender, recipient, amount, token, dstChainSelector); } - function _swapDataToBytes(IDexSwap.SwapData[] calldata _swapData) private pure returns (bytes memory _encodedData) { - if (_swapData.length == 0) { - _encodedData = abi.encode(uint(0)); - } else { - _encodedData = abi.encode(_swapData[0]); - } - } - function _handleDstFunctionsResponse(Request storage request) internal { Transaction storage transaction = s_transactions[request.ccipMessageId]; @@ -261,14 +241,14 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { swapData.fromAmount = amount; swapDataArray[0] = swapData; - IParentPool(i_poolProxy).orchestratorLoan(tokenReceived, amount, address(this)); + IPool(i_poolProxy).orchestratorLoan(tokenReceived, amount, address(this)); (bool swapSuccess, bytes memory swapError) = i_dexSwap.delegatecall( abi.encodeWithSelector(IDexSwap.conceroEntry.selector, swapDataArray, 0, transaction.recipient) ); if (swapSuccess == false) revert TXReleasedFailed(swapError); } else { - IParentPool(i_poolProxy).orchestratorLoan(tokenReceived, amount, transaction.recipient); + IPool(i_poolProxy).orchestratorLoan(tokenReceived, amount, transaction.recipient); } emit TXReleased(request.ccipMessageId, transaction.sender, transaction.recipient, tokenReceived, amount); @@ -290,4 +270,20 @@ contract ConceroFunctions is FunctionsClient, ConceroCommon, Storage { s_latestNativeUsdcRate = nativeUsdcRate == 0 ? s_latestNativeUsdcRate : nativeUsdcRate; s_latestLinkNativeRate = linkNativeRate == 0 ? s_latestLinkNativeRate : linkNativeRate; } + + ///////////////////////////// + /// VIEW & PURE FUNCTIONS /// + ///////////////////////////// + function _swapDataToBytes(IDexSwap.SwapData[] calldata _swapData) private pure returns (bytes memory _encodedData) { + if (_swapData.length == 0) { + _encodedData = abi.encode(uint(0)); + } else { + _encodedData = abi.encode(_swapData[0]); + } + } + + function getDstTotalFeeInUsdc(uint256 amount) public pure returns (uint256) { + return amount / 1000; + //@audit we can have loss of precision here? + } } diff --git a/packages/hardhat/contracts/DexSwap.sol b/packages/hardhat/contracts/DexSwap.sol index 02c1769a4..f89e0876e 100644 --- a/packages/hardhat/contracts/DexSwap.sol +++ b/packages/hardhat/contracts/DexSwap.sol @@ -7,13 +7,11 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; import {ISwapRouter} from "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; import {ISwapRouter as ISushiRouterV3} from "sushiswap-v3-periphery/contracts/interfaces/ISwapRouter.sol"; -import {TransferHelper} from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; import {IRouter} from "velodrome/contracts/interfaces/IRouter.sol"; import {ISwapRouter02, IV3SwapRouter} from "./Interfaces/ISwapRouter02.sol"; import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol"; import {Storage} from "./Libraries/Storage.sol"; import {IDexSwap} from "./Interfaces/IDexSwap.sol"; -import {LibConcero} from "./Libraries/LibConcero.sol"; //////////////////////////////////////////////////////// //////////////////////// ERRORS //////////////////////// @@ -28,10 +26,6 @@ error DexSwap_RouterNotAllowed(); error DexSwap_InvalidPath(); ///@notice error emitted if a swapData has invalid tokens error DexSwap_SwapDataNotChained(address toToken, address fromToken); -///@notice error emitted if a not-owner-address call the function -error DexSwap_CallableOnlyByOwner(address caller, address owner); -///@notice error emitted when the DexData is not valid -error DexSwap_InvalidDexData(); contract DexSwap is IDexSwap, Storage { using SafeERC20 for IERC20; @@ -48,18 +42,11 @@ contract DexSwap is IDexSwap, Storage { /////////////// ///IMMUTABLE/// /////////////// + ///@notice immutable variable to infra-proxy address. address private immutable i_proxy; ///@notice immutable variable to hold wEth address address private immutable i_wEth; - //////////////////////////////////////////////////////// - //////////////////////// EVENTS //////////////////////// - //////////////////////////////////////////////////////// - ///@notice event emitted when the orchestrator address is updated - event DexSwap_OrchestratorContractUpdated(address previousAddress, address orchestrator); - ///@notice event emitted when value locked in the contract is removed - event DexSwap_RemovingDust(address receiver, uint256 amount); - ///////////////////////////////////////////////////////////////// ////////////////////////////FUNCTIONS//////////////////////////// ///////////////////////////////////////////////////////////////// diff --git a/packages/hardhat/contracts/Interfaces/IDexSwap.sol b/packages/hardhat/contracts/Interfaces/IDexSwap.sol index ca5ab9153..02439fdc7 100644 --- a/packages/hardhat/contracts/Interfaces/IDexSwap.sol +++ b/packages/hardhat/contracts/Interfaces/IDexSwap.sol @@ -15,8 +15,6 @@ interface IDexSwap { UniswapV2Ether } - error InvalidSwapData(); - ///@notice Concero Struct to track DEX Data struct SwapData { DexType dexType; diff --git a/packages/hardhat/contracts/Interfaces/IParentPool.sol b/packages/hardhat/contracts/Interfaces/IPool.sol similarity index 89% rename from packages/hardhat/contracts/Interfaces/IParentPool.sol rename to packages/hardhat/contracts/Interfaces/IPool.sol index 08440c87b..28542de5e 100644 --- a/packages/hardhat/contracts/Interfaces/IParentPool.sol +++ b/packages/hardhat/contracts/Interfaces/IPool.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.20; -interface IParentPool { +interface IPool { /////////////////////// ///TYPE DECLARATIONS/// /////////////////////// @@ -48,11 +48,5 @@ interface IParentPool { ///////////////////////////////////////////////////////////////////////////// function orchestratorLoan(address _token, uint256 _amount, address _receiver) external; - function withdrawLiquidityRequest(address _token, uint256 _amount) external; - - function depositEther() external payable; - - function depositToken(address _token, uint256 _amount) external; - function getPendingWithdrawRequest(address _liquidityProvider) external view returns (WithdrawRequests memory); } diff --git a/packages/hardhat/contracts/LPToken.sol b/packages/hardhat/contracts/LPToken.sol index 250a9d3a3..10ac1e0b2 100644 --- a/packages/hardhat/contracts/LPToken.sol +++ b/packages/hardhat/contracts/LPToken.sol @@ -2,10 +2,10 @@ // Compatible with OpenZeppelin Contracts ^5.0.0 pragma solidity 0.8.20; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; -import "@openzeppelin/contracts/access/AccessControl.sol"; -import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; +import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; +import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; +import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; contract LPToken is ERC20, ERC20Burnable, AccessControl, ERC20Permit { bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); diff --git a/packages/hardhat/contracts/Libraries/ParentStorage.sol b/packages/hardhat/contracts/Libraries/ParentStorage.sol index 055c18180..dd5411664 100644 --- a/packages/hardhat/contracts/Libraries/ParentStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentStorage.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.20; -import {IParentPool} from "contracts/Interfaces/IParentPool.sol"; +import {IPool} from "contracts/Interfaces/IPool.sol"; contract ParentStorage { ///////////////////// @@ -29,14 +29,14 @@ contract ParentStorage { ///STORAGE/// ///////////// ///@notice array of Pools to receive Liquidity through `ccipSend` function - IParentPool.Pools[] s_poolsToDistribute; + IPool.Pools[] s_poolsToDistribute; ///@notice Mapping to keep track of allowed pool receiver mapping(uint64 chainSelector => address pool) public s_poolToSendTo; ///@notice Mapping to keep track of allowed pool senders mapping(uint64 chainSelector => mapping(address poolAddress => uint256)) public s_contractsToReceiveFrom; ///@notice Mapping to keep track of Liquidity Providers withdraw requests - mapping(address _liquidityProvider => IParentPool.WithdrawRequests) public s_pendingWithdrawRequests; + mapping(address _liquidityProvider => IPool.WithdrawRequests) public s_pendingWithdrawRequests; ///@notice Mapping to keep track of Chainlink Functions requests - mapping(bytes32 requestId => IParentPool.CLFRequest) public s_requests; + mapping(bytes32 requestId => IPool.CLFRequest) public s_requests; } diff --git a/packages/hardhat/contracts/Libraries/Storage.sol b/packages/hardhat/contracts/Libraries/Storage.sol index f661d4c36..090627dc0 100644 --- a/packages/hardhat/contracts/Libraries/Storage.sol +++ b/packages/hardhat/contracts/Libraries/Storage.sol @@ -3,9 +3,7 @@ pragma solidity 0.8.20; import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; -import {IDexSwap} from "../Interfaces/IDexSwap.sol"; import {IStorage} from "../Interfaces/IStorage.sol"; -import {ConceroCCIP} from "../ConceroCCIP.sol"; abstract contract Storage is ReentrancyGuard, IStorage { @@ -34,9 +32,6 @@ abstract contract Storage is ReentrancyGuard, IStorage { ///////////// ///STORAGE/// ///////////// - ///@notice array of Pools to receive Liquidity through `ccipSend` function - Pools[] poolsToDistribute; - ///@notice Concero: Mapping to keep track of CLF fees for different chains mapping(uint64 => uint256) public clfPremiumFees; ///@notice DexSwap: mapping to keep track of allowed routers to perform swaps. 1 == Allowed. diff --git a/packages/hardhat/contracts/Libraries/StorageSetters.sol b/packages/hardhat/contracts/Libraries/StorageSetters.sol index e4f7679c6..78502e18b 100644 --- a/packages/hardhat/contracts/Libraries/StorageSetters.sol +++ b/packages/hardhat/contracts/Libraries/StorageSetters.sol @@ -10,34 +10,30 @@ contract StorageSetters is Storage { ///@notice error emitted when the input is the address(0) error StorageSetters_InvalidAddress(); + ///@notice error emitted when a non-owner address call access controlled functions error StorageSetters_CallableOnlyByOwner(address msgSender, address owner); - /////////////// - ///CONSTANTS/// - /////////////// - /////////////// ///IMMUTABLE/// /////////////// address internal immutable i_owner; + ///@notice event emitted when the CLF Premium fee is updated event CLFPremiumFeeUpdated(uint64 chainSelector, uint256 previousValue, uint256 feeAmount); + ///@notice event emitted when a new Concero Contract is added or updated event ConceroContractUpdated(uint64 chainSelector, address conceroContract); + ///@notice event emitted when the CLF secret is updated event DonSecretVersionUpdated(uint64 previousDonSecretVersion, uint64 newDonSecretVersion); + ///@notice event emitted when the CLF slot id is updated event DonSlotIdUpdated(uint8 previousDonSlot, uint8 newDonSlot); + ///@notice event emitted when the Destination JS Hash Sum is updated event DestinationJsHashSumUpdated(bytes32 previousDstHashSum, bytes32 newDstHashSum); + ///@notice event emitted when the Source JS Hash Sum is updated event SourceJsHashSumUpdated(bytes32 previousSrcHashSum, bytes32 newSrcHashSum); + ///@notice event emitted when the Ethers hash sum is updated event EthersHashSumUpdated(bytes32 previousValue, bytes32 hashSum); ///@notice event emitted when a new router address is added event Storage_NewRouterAdded(address router, uint256 isApproved); - ///@notice event emitted a cross-chain Gas price is updated. - event StorageSetters_LastGasPriceUpdated(uint64 chainSelector, uint256 feeAmount); - ///@notice event emitted when the Link to Usdc rate is updated - event StorageSetters_LinkUsdcRateUpdated(uint256 amount); - ///@notice event emitted when the Native to Usdc rate is updated - event StorageSetters_NativeUsdcRateUpdated(uint256 amount); - ///@notice event emitted when the Link to Native rate is updated - event StorageSetters_LinkNativeRateUpdated(uint256 amount); constructor(address _initialOwner) { i_owner = _initialOwner; @@ -101,13 +97,13 @@ contract StorageSetters is Storage { /// CONTRACT ADDRESSES/// ///////////////////////// function setConceroContract(uint64 _chainSelector, address _conceroContract) external onlyOwner { - if(_conceroContract == address(0)) revert StorageSetters_InvalidAddress(); + if (_conceroContract == address(0)) revert StorageSetters_InvalidAddress(); s_conceroContracts[_chainSelector] = _conceroContract; emit ConceroContractUpdated(_chainSelector, _conceroContract); } function setDstConceroPool(uint64 _chainSelector, address _pool) external payable onlyOwner { - if(_pool == address(0)) revert StorageSetters_InvalidAddress(); + if (_pool == address(0)) revert StorageSetters_InvalidAddress(); s_poolReceiver[_chainSelector] = _pool; } @@ -117,8 +113,8 @@ contract StorageSetters is Storage { * @param _isApproved 1 == Approved | Any other value is not Approved. */ function setDexRouterAddress(address _router, uint256 _isApproved) external payable onlyOwner { - if(_router == address(0)) revert StorageSetters_InvalidAddress(); + if (_router == address(0)) revert StorageSetters_InvalidAddress(); s_routerAllowed[_router] = _isApproved; emit Storage_NewRouterAdded(_router, _isApproved); } -} +} \ No newline at end of file diff --git a/packages/hardhat/contracts/Orchestrator.sol b/packages/hardhat/contracts/Orchestrator.sol index d87cb99ec..24f1b9579 100644 --- a/packages/hardhat/contracts/Orchestrator.sol +++ b/packages/hardhat/contracts/Orchestrator.sol @@ -86,6 +86,7 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage modifier validateBridgeData(BridgeData memory _bridgeData) { if (_bridgeData.amount == 0 || _bridgeData.dstChainSelector == 0 || _bridgeData.receiver == address(0)) revert Orchestrator_InvalidBridgeData(); + if (_bridgeData.tokenType != CCIPToken.usdc && _bridgeData.tokenType != CCIPToken.bnm) revert Orchestrator_InvalidBridgeToken(); _; } @@ -114,25 +115,6 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage //////////////////// ///DELEGATE CALLS/// //////////////////// - - //////////////////////// - /////VIEW FUNCTIONS///// - //////////////////////// - - function getSrcTotalFeeInUsdc(CCIPToken tokenType, uint64 dstChainSelector, uint256 amount) external view returns (uint256) { - return IOrchestratorViewDelegate(address(this)).getSrcTotalFeeInUsdcViaDelegateCall(tokenType, dstChainSelector, amount); - } - - function getSrcTotalFeeInUsdcViaDelegateCall(CCIPToken tokenType, uint64 dstChainSelector, uint256 amount) external returns (uint256) { - (bool success, bytes memory data) = i_concero.delegatecall( - abi.encodeWithSelector(IConcero.getSrcTotalFeeInUsdc.selector, tokenType, dstChainSelector, amount) - ); - - if (success == false) revert Orchestrator_UnableToCompleteDelegateCall(data); - - return _convertToUSDCDecimals(abi.decode(data, (uint256))); - } - function swapAndBridge( BridgeData memory bridgeData, IDexSwap.SwapData[] calldata srcSwapData, @@ -212,6 +194,19 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage emit Orchestrator_RequestFulfilled(requestId); } + function getSrcTotalFeeInUsdcViaDelegateCall(CCIPToken tokenType, uint64 dstChainSelector, uint256 amount) external returns (uint256) { + (bool success, bytes memory data) = i_concero.delegatecall( + abi.encodeWithSelector(IConcero.getSrcTotalFeeInUsdc.selector, tokenType, dstChainSelector, amount) + ); + + if (success == false) revert Orchestrator_UnableToCompleteDelegateCall(data); + + return _convertToUSDCDecimals(abi.decode(data, (uint256))); + } + + ////////////////////////// + /// EXTERNAL FUNCTIONS /// + ////////////////////////// function withdraw(address recipient, address token, uint256 amount) external payable onlyOwner { uint256 balance = LibConcero.getBalance(token, address(this)); if (balance < amount) revert Orchestrator_InvalidAmount(); @@ -267,6 +262,10 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage /////////////////////////// ///VIEW & PURE FUNCTIONS/// /////////////////////////// + function getSrcTotalFeeInUsdc(CCIPToken tokenType, uint64 dstChainSelector, uint256 amount) external view returns (uint256) { + return IOrchestratorViewDelegate(address(this)).getSrcTotalFeeInUsdcViaDelegateCall(tokenType, dstChainSelector, amount); + } + function getTransactionsInfo(bytes32 _ccipMessageId) external view returns (Transaction memory transaction) { transaction = s_transactions[_ccipMessageId]; } diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 3402df272..0e7cfba5a 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -11,7 +11,7 @@ import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/Fu import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/v1_0_0/libraries/FunctionsRequest.sol"; import {ConceroAutomation} from "./ConceroAutomation.sol"; import {LPToken} from "./LPToken.sol"; -import {IParentPool} from "contracts/Interfaces/IParentPool.sol"; +import {IPool} from "contracts/Interfaces/IPool.sol"; import {IStorage} from "./Interfaces/IStorage.sol"; import {ParentStorage} from "contracts/Libraries/ParentStorage.sol"; import {IOrchestrator} from "./Interfaces/IOrchestrator.sol"; @@ -90,7 +90,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { ///@notice Chainlink Link Token interface LinkTokenInterface private immutable i_linkToken; ///@notice immutable variable to store the USDC address. - IERC20 immutable i_USDC; + IERC20 private immutable i_USDC; ///@notice Pool liquidity token LPToken public immutable i_lp; ///@notice Concero Automation contract @@ -100,7 +100,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { ///@notice Chainlink Functions Protocol Subscription ID uint64 private immutable i_subscriptionId; ///@notice Contract Owner - address immutable i_owner; + address private immutable i_owner; //////////////////////////////////////////////////////// //////////////////////// EVENTS //////////////////////// @@ -118,7 +118,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { ///@notice event emitted when a request is updated with the total USDC to withdraw event ParentPool_RequestUpdated(address liquidityProvider); ///@notice event emitted when the Functions request return error - event FunctionsRequestError(bytes32 requestId, IParentPool.RequestType requestType); + event FunctionsRequestError(bytes32 requestId, IPool.RequestType requestType); ///@notice event emitted when a Concero pool is added event ParentPool_PoolReceiverUpdated(uint64 chainSelector, address pool); ///@notice event emitted when a allowed Cross-chain contract is updated @@ -228,8 +228,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { args[1] = abi.encodePacked(s_ethersHashSum); bytes32 requestId = _sendRequest(args, JS_CODE); - s_requests[requestId] = IParentPool.CLFRequest({ - requestType: IParentPool.RequestType.GetTotalUSDC, + s_requests[requestId] = IPool.CLFRequest({ + requestType: IPool.RequestType.GetTotalUSDC, liquidityProvider: msg.sender, usdcBeforeRequest: i_USDC.balanceOf(address(this)) + s_loansInUse, lpSupplyBeforeRequest: i_lp.totalSupply(), @@ -258,8 +258,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { bytes32 requestId = _sendRequest(args, JS_CODE); - s_requests[requestId] = IParentPool.CLFRequest({ - requestType: IParentPool.RequestType.PerformWithdrawal, + s_requests[requestId] = IPool.CLFRequest({ + requestType: IPool.RequestType.PerformWithdrawal, liquidityProvider: msg.sender, usdcBeforeRequest: 0, lpSupplyBeforeRequest: i_lp.totalSupply(), @@ -276,7 +276,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * the withdraw will be finalize. If not, it must revert */ function completeWithdrawal() external isProxy { - IParentPool.WithdrawRequests memory withdraw = s_pendingWithdrawRequests[msg.sender]; + IPool.WithdrawRequests memory withdraw = s_pendingWithdrawRequests[msg.sender]; if (withdraw.amountToReceive > 0) revert ParentPool_AmountNotAvailableYet(withdraw.amountToReceive); if (withdraw.amountEarned > i_USDC.balanceOf(address(this))) revert ParentPool_InsufficientBalance(); @@ -326,7 +326,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { */ function setPoolsToSend(uint64 _chainSelector, address _pool) external payable onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); - s_poolsToDistribute.push(IParentPool.Pools({chainSelector: _chainSelector, poolAddress: _pool})); + s_poolsToDistribute.push(IPool.Pools({chainSelector: _chainSelector, poolAddress: _pool})); s_poolToSendTo[_chainSelector] = _pool; @@ -406,7 +406,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { s_loansInUse = s_loansInUse - amountMinusFees; } } else if (_liquidityProvider != address(0)) { - IParentPool.WithdrawRequests storage request = s_pendingWithdrawRequests[_liquidityProvider]; + IPool.WithdrawRequests storage request = s_pendingWithdrawRequests[_liquidityProvider]; //update the corresponding withdraw request request.amountToReceive = request.amountToReceive >= any2EvmMessage.destTokenAmounts[0].amount @@ -431,7 +431,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { */ function _ccipSend(uint256 _numberOfPools, uint256 _amountToDistribute) internal returns (bytes32 messageId) { for (uint256 i; i < _numberOfPools; ) { - IParentPool.Pools memory pool = s_poolsToDistribute[i]; + IPool.Pools memory pool = s_poolsToDistribute[i]; Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToDistribute, pool.poolAddress); @@ -488,7 +488,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev response & err will never be empty or populated at same time. */ function fulfillRequest(bytes32 requestId, bytes memory response, bytes memory err) internal override { - IParentPool.CLFRequest storage request = s_requests[requestId]; + IPool.CLFRequest storage request = s_requests[requestId]; if (err.length > 0) { emit FunctionsRequestError(requestId, request.requestType); @@ -498,17 +498,13 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { uint256 crossChainBalance = abi.decode(response, (uint256)); uint256 usdcReserve = request.usdcBeforeRequest + crossChainBalance; - if (request.requestType == IParentPool.RequestType.GetTotalUSDC) { + if (request.requestType == IPool.RequestType.GetTotalUSDC) { _updateDepositInfoAndMintLPTokens(request.liquidityProvider, request.lpSupplyBeforeRequest, request.amount, usdcReserve); - } else if (request.requestType == IParentPool.RequestType.PerformWithdrawal) { + } else if (request.requestType == IPool.RequestType.PerformWithdrawal) { _updateUsdcAmountEarned(request.liquidityProvider, request.lpSupplyBeforeRequest, request.amount, usdcReserve); } } - function getPendingWithdrawRequest(address _liquidityProvider) external view returns (IParentPool.WithdrawRequests memory) { - return s_pendingWithdrawRequests[_liquidityProvider]; - } - /////////////// /// PRIVATE /// /////////////// @@ -561,7 +557,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { uint256 amountToWithdrawWithUsdcDecimals = _convertToUSDCTokenDecimals(amountToWithdraw); - IParentPool.WithdrawRequests memory request = IParentPool.WithdrawRequests({ + IPool.WithdrawRequests memory request = IPool.WithdrawRequests({ amountEarned: amountToWithdrawWithUsdcDecimals, amountToBurn: _lpToBurn, amountToRequest: amountToWithdrawWithUsdcDecimals / (numberOfPools + 1), //Cross-chain Pools + MasterPool @@ -587,7 +583,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // uint256 lastBaseGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); // for(uint256 i; i < numberOfPools; ){ - // IParentPool.Pools memory pool = s_poolsToDistribute[i]; + // IPool.Pools memory pool = s_poolsToDistribute[i]; // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), pool.poolAddress); // //Link cost for all transactions @@ -615,7 +611,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // uint256 costOfCCIPSendToPoolExecution; // for(uint256 i; i < numberOfPools; ){ - // IParentPool.Pools memory pool = s_poolsToDistribute[i]; + // IPool.Pools memory pool = s_poolsToDistribute[i]; // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToReceive, address(this)); // //Link cost for all transactions @@ -667,6 +663,10 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { _adjustedAmount = (_lpAmount * USDC_DECIMALS) / LP_TOKEN_DECIMALS; } + function getPendingWithdrawRequest(address _liquidityProvider) external view returns (IPool.WithdrawRequests memory) { + return s_pendingWithdrawRequests[_liquidityProvider]; + } + function getMaxCap() external view returns (uint256 _maxCap) { _maxCap = s_maxDeposit; } diff --git a/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol b/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol index 72bfab928..36045f375 100644 --- a/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol +++ b/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol @@ -6,7 +6,6 @@ pragma solidity ^0.8.20; import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol"; -import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {ChildStorage} from "../Libraries/ChildStorage.sol"; diff --git a/packages/hardhat/contracts/Proxy/InfraProxy.sol b/packages/hardhat/contracts/Proxy/InfraProxy.sol index 9010d4356..76ed4918c 100644 --- a/packages/hardhat/contracts/Proxy/InfraProxy.sol +++ b/packages/hardhat/contracts/Proxy/InfraProxy.sol @@ -6,7 +6,6 @@ pragma solidity ^0.8.20; import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol"; -import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {Storage} from "../Libraries/Storage.sol"; diff --git a/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol b/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol index e8c0a6bde..c95e96e24 100644 --- a/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol +++ b/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol @@ -6,7 +6,6 @@ pragma solidity ^0.8.20; import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol"; -import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {ParentStorage} from "../Libraries/ParentStorage.sol"; From 9734e874f5c9b735663f12351c89c22782e8cdb1 Mon Sep 17 00:00:00 2001 From: Barba Date: Thu, 11 Jul 2024 21:57:32 -0300 Subject: [PATCH 03/17] Rebalancing system Setup --- .../hardhat/contracts/ConceroChildPool.sol | 30 +++++-- .../contracts/Libraries/ChildStorage.sol | 1 + packages/hardhat/contracts/ParentPool.sol | 85 +++++++++++++++---- 3 files changed, 91 insertions(+), 25 deletions(-) diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index c91cd2c70..cdc4ba2c2 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -54,8 +54,6 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { LinkTokenInterface private immutable i_linkToken; ///@notice immutable variable to store the USDC address. IERC20 private immutable i_USDC; - ///@notice immutable variable to store the MasterPool chain selector - uint64 private immutable i_parentPoolChainSelector; ///@notice immutable variable to store the MasterPool Proxy address address private immutable i_parentPoolProxyAddress; ///@notice Contract Owner @@ -72,6 +70,8 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { event ConceroChildPool_LoanTaken(address receiver, uint256 amount); ///@notice event emitted when a allowed Cross-chain contract is updated event ConceroChildPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256 isAllowed); + ///@notice event emitted when a new pool is added + event ConceroChildPool_PoolReceiverUpdated(uint64 chainSelector, address pool); /////////////// ///MODIFIERS/// @@ -141,7 +141,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @param _amount amount of the token to be sent * @dev This function will sent the address of the user as data. This address will be used to update the mapping on MasterPool. */ - function ccipSendToPool(address _liquidityProviderAddress, uint256 _amount) external onlyMessenger isProxy returns (bytes32 messageId) { + function ccipSendToPool(uint64 _chainSelector, address _liquidityProviderAddress, uint256 _amount) external onlyMessenger isProxy returns (bytes32 messageId) { if (_amount > i_USDC.balanceOf(address(this))) revert ConceroChildPool_InsufficientBalance(); Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); @@ -151,23 +151,23 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { tokenAmounts[0] = tokenAmount; Client.EVM2AnyMessage memory evm2AnyMessage = Client.EVM2AnyMessage({ - receiver: abi.encode(i_parentPoolProxyAddress), + receiver: abi.encode(s_poolToSendTo[_chainSelector]), data: abi.encode(_liquidityProviderAddress, address(0), 0), //0== lp fee. It will always be zero because here we just processing withdraws tokenAmounts: tokenAmounts, extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 300_000})), feeToken: address(i_linkToken) }); - uint256 fees = IRouterClient(i_ccipRouter).getFee(i_parentPoolChainSelector, evm2AnyMessage); + uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); if (fees > i_linkToken.balanceOf(address(this))) revert ConceroChildPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); i_USDC.approve(i_ccipRouter, _amount); i_linkToken.approve(i_ccipRouter, fees); - emit ConceroChildPool_MessageSent(messageId, i_parentPoolChainSelector, i_parentPoolProxyAddress, address(i_linkToken), fees); + emit ConceroChildPool_MessageSent(messageId, _chainSelector, s_poolToSendTo[_chainSelector], address(i_linkToken), fees); - messageId = IRouterClient(i_ccipRouter).ccipSend(i_parentPoolChainSelector, evm2AnyMessage); + messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); } /** @@ -209,6 +209,22 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { emit ConceroChildPool_ConceroSendersUpdated(_chainSelector, _contractAddress, _isAllowed); } + /** + * @notice function to manage the Cross-chain ConceroPool contracts + * @param _chainSelector chain identifications + * @param _pool address of the Cross-chain ConceroPool contract + * @dev only owner can call it + * @dev it's payable to save some gas. + * @dev this functions is used on ConceroPool.sol + */ + function setPoolsToSend(uint64 _chainSelector, address _pool) external payable onlyOwner { + if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroChildPool_InvalidAddress(); + + s_poolToSendTo[_chainSelector] = _pool; + + emit ConceroChildPool_PoolReceiverUpdated(_chainSelector, _pool); + } + //////////////// /// INTERNAL /// //////////////// diff --git a/packages/hardhat/contracts/Libraries/ChildStorage.sol b/packages/hardhat/contracts/Libraries/ChildStorage.sol index ddb8aeb63..b9352c530 100644 --- a/packages/hardhat/contracts/Libraries/ChildStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildStorage.sol @@ -15,4 +15,5 @@ contract ChildStorage { ///////////// ///@notice Mapping to keep track of allowed pool senders mapping(uint64 chainSelector => mapping(address conceroContract => uint256)) public s_contractsToReceiveFrom; + mapping(uint64 chainSelector => address pools) public s_poolToSendTo; } diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 0e7cfba5a..71e170e87 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -24,6 +24,8 @@ import {Orchestrator} from "./Orchestrator.sol"; error ParentPool_InsufficientBalance(); ///@notice error emitted when the receiver is the address(0) error ParentPool_InvalidAddress(); +///@notice error emitted when the caller is not a valid Messenger +error ParentPool_NotMessenger(address caller); ///@notice error emitted when the CCIP message sender is not allowed. error ParentPool_SenderNotAllowed(address _sender); ///@notice error emitted when an attempt to create a new request is made while other is still active. @@ -156,6 +158,14 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { _; } + /** + * @notice modifier to check if the caller is the an approved messenger + */ + modifier onlyMessenger() { + if (isMessenger(msg.sender) == false) revert ParentPool_NotMessenger(msg.sender); + _; + } + ///////////////////////////////////////////////////////////////////////////// //////////////////////////////////FUNCTIONS////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// @@ -241,7 +251,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { i_USDC.safeTransferFrom(msg.sender, address(this), _usdcAmount); // i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(depositFee)); - _ccipSend(numberOfPools, amountToDistribute); + _distributeLiquidity(numberOfPools, amountToDistribute); } /** @@ -297,6 +307,12 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { i_USDC.safeTransfer(msg.sender, withdraw.amountEarned); } + function rebalancePools(uint64 _chainSelector, uint256 _amountToSend) external onlyMessenger{ + if(s_poolsToSendTo[_chainSelector] == address(0)) revert ParentPool_InvalidAddress(); + + _ccipSend(_chainSelector, s_poolToSendTo[_chainSelector], _amountToSend); + } + /////////////////////// ///SETTERS FUNCTIONS/// /////////////////////// @@ -364,8 +380,10 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @param _chainSelector the CCIP chainSelector for the specific chain */ function removePoolsFromListOfSenders(uint64 _chainSelector) external payable onlyOwner { + address removedPool; for (uint256 i; i < s_poolsToDistribute.length; ) { if (s_poolsToDistribute[i].chainSelector == _chainSelector) { + removedPool = s_poolToSendTo[_chainSelector]; s_poolsToDistribute[i] = s_poolsToDistribute[s_poolsToDistribute.length - 1]; s_poolsToDistribute.pop(); delete s_poolToSendTo[_chainSelector]; @@ -375,6 +393,10 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { } } emit ParentPool_ChainAndAddressRemoved(_chainSelector); + + //send through functions? + //_chainSelector / removedPool / s_poolsToDistribute.length +1 (ParentPool included) + // functions query balance, divide by number of pools left and trigger the transfer in each chain } //////////////// @@ -426,30 +448,39 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { } /** - * @notice Function to distribute funds automatically right after LP deposits into the pool - * @dev this function will only be called internally. + * @notice helper function to distribute liquidity after LP deposits. + * @param _numberOfPools number of pools to receive liquidity + * @param _amountToDistribute amount of USDC should be distributed to the pools. */ - function _ccipSend(uint256 _numberOfPools, uint256 _amountToDistribute) internal returns (bytes32 messageId) { + function _distributeLiquidity(uint256 _numberOfPools, uint256 _amountToDistribute) internal { for (uint256 i; i < _numberOfPools; ) { IPool.Pools memory pool = s_poolsToDistribute[i]; - Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToDistribute, pool.poolAddress); + _ccipSend(pool.chainSelector, pool.poolAddress, _amountToDistribute); - uint256 fees = IRouterClient(i_ccipRouter).getFee(pool.chainSelector, evm2AnyMessage); + unchecked { + ++i; + } + } + } - if (fees > i_linkToken.balanceOf(address(this))) revert ParentPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); + /** + * @notice Function to distribute funds automatically right after LP deposits into the pool + * @dev this function will only be called internally. + */ + function _ccipSend(uint64 _chainSelector, address _poolAddress, uint256 _amountToDistribute) internal returns (bytes32 messageId) { + Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToDistribute, _poolAddress); - i_USDC.approve(i_ccipRouter, _amountToDistribute); - i_linkToken.approve(i_ccipRouter, fees); + uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); - messageId = IRouterClient(i_ccipRouter).ccipSend(pool.chainSelector, evm2AnyMessage); + if (fees > i_linkToken.balanceOf(address(this))) revert ParentPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); - emit ParentPool_MessageSent(messageId, pool.chainSelector, pool.poolAddress, address(i_linkToken), fees); + i_USDC.approve(i_ccipRouter, _amountToDistribute); + i_linkToken.approve(i_ccipRouter, fees); - unchecked { - ++i; - } - } + messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); + + emit ParentPool_MessageSent(messageId, _chainSelector, _poolAddress, address(i_linkToken), fees); } function _buildCCIPMessage(address _token, uint256 _amount, address _poolAddress) internal view returns (Client.EVM2AnyMessage memory) { @@ -675,8 +706,26 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { _usdcInUse = s_loansInUse; } - // TODO: Remove this function after tests - function deletePendingWithdrawRequest(address _liquidityProvider) external isProxy onlyOwner { - delete s_pendingWithdrawRequests[_liquidityProvider]; + /** + * @notice Function to check if a caller address is an allowed messenger + * @param _messenger the address of the caller + */ + function isMessenger(address _messenger) internal pure returns (bool isMessenger) { + address[] memory messengers = new address[](4); //Number of messengers. To define. + messengers[0] = 0x11111003F38DfB073C6FeE2F5B35A0e57dAc4715; + messengers[1] = 0x05CF0be5cAE993b4d7B70D691e063f1E0abeD267; + messengers[2] = address(0); + messengers[3] = address(0); + + for (uint256 i; i < messengers.length; ) { + if (_messenger == messengers[i]) { + return true; + } + unchecked { + ++i; + } + } + return false; } + } From fe35134f3d41b6e10337c5f679e1d1fa1f9ef78e Mon Sep 17 00:00:00 2001 From: Barba Date: Fri, 12 Jul 2024 15:13:07 -0300 Subject: [PATCH 04/17] Implement Solidity part of Add&Remove Pools mechanism --- packages/foundry/script/ChildPoolDeploy.s.sol | 2 - .../script/TestnetChildPoolDeploy.s.sol | 4 +- .../IntegrationTests/InfraIntegration.t.sol | 3 +- .../MainnetFork/ProtocolMainnet.t.sol | 3 +- .../TestnetFork/ProtocolTestnet.t.sol | 9 ++- .../UnitTests/ConceroChildPool.t.sol | 3 +- .../UnitTests/ParentPool.t.sol | 16 ++--- .../hardhat/contracts/ConceroChildPool.sol | 10 ++- packages/hardhat/contracts/ParentPool.sol | 72 +++++++++++++++---- 9 files changed, 79 insertions(+), 43 deletions(-) diff --git a/packages/foundry/script/ChildPoolDeploy.s.sol b/packages/foundry/script/ChildPoolDeploy.s.sol index d357e4da2..67fcf574d 100644 --- a/packages/foundry/script/ChildPoolDeploy.s.sol +++ b/packages/foundry/script/ChildPoolDeploy.s.sol @@ -13,7 +13,6 @@ contract ChildPoolDeploy is Script { address _childProxy, address _link, address _ccipRouter, - uint64 _destinationChainSelector, address _usdc, address _owner ) public returns(ConceroChildPool child){ @@ -24,7 +23,6 @@ contract ChildPoolDeploy is Script { _childProxy, _link, _ccipRouter, - _destinationChainSelector, _usdc, _owner ); diff --git a/packages/foundry/script/TestnetChildPoolDeploy.s.sol b/packages/foundry/script/TestnetChildPoolDeploy.s.sol index ffc3878d3..7322c043a 100644 --- a/packages/foundry/script/TestnetChildPoolDeploy.s.sol +++ b/packages/foundry/script/TestnetChildPoolDeploy.s.sol @@ -11,7 +11,6 @@ contract TestnetChildPoolDeploy is Script { address _childProxy = 0xb9b4eb0088cD3d98fF7A30a8e7DeE5eCdcC290B2; address _link = 0xE4aB69C077896252FAFBD49EFD26B5D171A32410; address _ccipRouter = 0xD3b06cEbF099CE7DA4AcCf578aaebFDBd6e88a93; - uint64 _destinationChainSelector = 10344971235874465080; address _usdc = 0x036CbD53842c5426634e7929541eC2318f3dCF7e; address _owner = 0x5FA769922a6428758fb44453815e2c436c57C3c7; @@ -22,8 +21,7 @@ contract TestnetChildPoolDeploy is Script { _masterPoolProxyAddress, _childProxy, _link, - _ccipRouter, - _destinationChainSelector, + _ccipRouter, _usdc, _owner ); diff --git a/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol b/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol index ada25a612..4a98bf5b6 100644 --- a/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol @@ -369,7 +369,6 @@ contract InfraIntegration is Test { address(childProxy), link, ccipRouterLocalDst, - localChainSelector, address(mUSDC), Tester ); @@ -409,7 +408,7 @@ contract InfraIntegration is Test { //Parent Pool wMaster.setConceroContractSender(localChainSelector, address(wChild), 1); - wMaster.setPoolsToSend(localChainSelector, address(wChild)); + wMaster.setPoolsToSend(localChainSelector, address(wChild), false); //Child Pool wChild.setConceroContractSender(localChainSelector, address(wMaster), 1); diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index c267dc6a0..8aed23074 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -429,7 +429,6 @@ contract ProtocolMainnet is Test { address(childProxy), linkArb, ccipRouterArb, - baseChainSelector, address(aUSDC), Tester ); @@ -475,7 +474,7 @@ contract ProtocolMainnet is Test { //====== Setters ///== Pools vm.startPrank(Tester); - wMaster.setPoolsToSend(arbChainSelector, address(childProxy)); + wMaster.setPoolsToSend(arbChainSelector, address(childProxy), false); assertEq(wMaster.s_poolToSendTo(arbChainSelector), address(wChild)); wMaster.setConceroContractSender(arbChainSelector, address(wChild), 1); diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index 2b8ce213c..89375a0ed 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -392,7 +392,6 @@ contract ProtocolTestnet is Test { address(childProxy), linkArb, ccipRouterArb, - baseChainSelector, address(ccipBnMArb), Tester ); @@ -433,7 +432,7 @@ contract ProtocolTestnet is Test { ///======= Pools Allowance vm.startPrank(Tester); - wMaster.setPoolsToSend(arbChainSelector, address(childProxy)); + wMaster.setPoolsToSend(arbChainSelector, address(childProxy), false); assertEq(wMaster.s_poolToSendTo(arbChainSelector), address(wChild)); wMaster.setConceroContractSender(arbChainSelector, address(wChild), 1); @@ -888,20 +887,20 @@ contract ProtocolTestnet is Test { function test_ccipSendToPool() public { vm.prank(Messenger); vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_InsufficientBalance.selector)); - wChild.ccipSendToPool(Tester, 10*10**6); + wChild.ccipSendToPool(baseChainSelector, Tester, 10*10**6); vm.prank(0xd5CCdabF11E3De8d2F64022e232aC18001B8acAC); ERC20Mock(ccipBnMArb).mint(address(wChild), 1000 * 10**6); vm.prank(Messenger); vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_NotEnoughLinkBalance.selector, 0, 7043276117429745)); - wChild.ccipSendToPool(Tester, 10*10**6); + wChild.ccipSendToPool(baseChainSelector, Tester, 10*10**6); vm.prank(0x4281eCF07378Ee595C564a59048801330f3084eE); LinkToken(linkArb).transfer(address(wChild), 10*10**18); vm.prank(Messenger); - wChild.ccipSendToPool(Tester, 10*10**6); + wChild.ccipSendToPool(baseChainSelector, Tester, 10*10**6); } function test_orchestratorLoanRevertBecauseOfAmount() public setters { diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol index 63c703514..f7a099665 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol @@ -75,7 +75,6 @@ contract ConceroChildPoolTest is Test { address(childProxy), mockLinkTokenAddress, mockSourceRouter, - mockDestinationChainSelector, address(usdc), Tester ); @@ -161,6 +160,6 @@ contract ConceroChildPoolTest is Test { error ConceroChildPool_NotMessenger(address); function test_onlyMessengerCanCall() public { vm.expectRevert(abi.encodeWithSelector(ConceroChildPool_NotMessenger.selector, address(this))); - wChild.ccipSendToPool(Tester, 1000*10**6); + wChild.ccipSendToPool(mockDestinationChainSelector, Tester, 1000*10**6); } } diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol index 90859ba3b..0c95a820b 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol @@ -136,25 +136,25 @@ contract ParentPoolTest is Test { vm.prank(Tester); vm.expectEmit(); emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); assertEq(wMaster.s_poolToSendTo(mockDestinationChainSelector), address(mockChildPoolAddress)); } function test_revertSetParentPoolReceiver() public { vm.expectRevert(abi.encodeWithSelector(ParentPool_NotContractOwner.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(0)); + wMaster.setPoolsToSend(mockDestinationChainSelector, address(0), false); } ///orchestratorLoan/// @@ -187,7 +187,7 @@ contract ParentPoolTest is Test { //===== Add a Fake pool vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress); + wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress, false); //===== Cap is Zero vm.prank(Tester); @@ -211,7 +211,7 @@ contract ParentPoolTest is Test { wMaster.depositLiquidity(allowedAmountToDeposit); vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress); + wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress, false); // vm.prank(Tester); // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); @@ -233,7 +233,7 @@ contract ParentPoolTest is Test { event ParentPool_ChainAndAddressRemoved(uint64 chainSelector); function test_removePoolFromArray() public { vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectEmit(); diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index cdc4ba2c2..3089850a7 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -118,7 +118,6 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { address _childProxy, address _link, address _ccipRouter, - uint64 _destinationChainSelector, address _usdc, address _owner ) CCIPReceiver(_ccipRouter) { @@ -126,7 +125,6 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { i_childProxy = _childProxy; i_linkToken = LinkTokenInterface(_link); i_USDC = IERC20(_usdc); - i_parentPoolChainSelector = _destinationChainSelector; i_parentPoolProxyAddress = _masterPoolProxyAddress; i_owner = _owner; } @@ -136,11 +134,11 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { //////////////////////// /** - * @notice Function to Distribute Liquidity across Concero Pools - * @param _liquidityProviderAddress The liquidity provider that requested Withdraw + * @notice Function to Distribute Liquidity across Concero Pools and process withdrawals + * @param _liquidityProviderAddress The liquidity provider that requested Withdraw. If it's a rebalance, it will be address(0) * @param _amount amount of the token to be sent * @dev This function will sent the address of the user as data. This address will be used to update the mapping on MasterPool. - */ + */ function ccipSendToPool(uint64 _chainSelector, address _liquidityProviderAddress, uint256 _amount) external onlyMessenger isProxy returns (bytes32 messageId) { if (_amount > i_USDC.balanceOf(address(this))) revert ConceroChildPool_InsufficientBalance(); @@ -152,7 +150,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { Client.EVM2AnyMessage memory evm2AnyMessage = Client.EVM2AnyMessage({ receiver: abi.encode(s_poolToSendTo[_chainSelector]), - data: abi.encode(_liquidityProviderAddress, address(0), 0), //0== lp fee. It will always be zero because here we just processing withdraws + data: abi.encode(_liquidityProviderAddress, address(0), 0), //0== lp fee. It will always be zero because here we are only processing withdraws tokenAmounts: tokenAmounts, extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 300_000})), feeToken: address(i_linkToken) diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 71e170e87..0b36a6b4a 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -307,8 +307,14 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { i_USDC.safeTransfer(msg.sender, withdraw.amountEarned); } - function rebalancePools(uint64 _chainSelector, uint256 _amountToSend) external onlyMessenger{ - if(s_poolsToSendTo[_chainSelector] == address(0)) revert ParentPool_InvalidAddress(); + /** + * @notice Function called by Messenger to re-balance USDC between pools after and addition or exclusion + * @param _chainSelector the chain selector to be sent + * @param _notUsedHere in parent pool, is always address(0). We maintain it here so we can standardize the function to CLF calls. + * @param _amountToSend the amount to redistribute between pools. + */ + function ccipSendToPool(uint64 _chainSelector, address _notUsedHere, uint256 _amountToSend) external isProxy onlyMessenger { + if(s_poolToSendTo[_chainSelector] == address(0)) revert ParentPool_InvalidAddress(); _ccipSend(_chainSelector, s_poolToSendTo[_chainSelector], _amountToSend); } @@ -325,7 +331,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev it's payable to save some gas. * @dev this functions is used on ConceroPool.sol */ - function setConceroContractSender(uint64 _chainSelector, address _contractAddress, uint256 _isAllowed) external payable onlyOwner { + function setConceroContractSender(uint64 _chainSelector, address _contractAddress, uint256 _isAllowed) external payable isProxy onlyOwner { if (_contractAddress == address(0)) revert ParentPool_InvalidAddress(); s_contractsToReceiveFrom[_chainSelector][_contractAddress] = _isAllowed; @@ -340,38 +346,58 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev it's payable to save some gas. * @dev this functions is used on ConceroPool.sol */ - function setPoolsToSend(uint64 _chainSelector, address _pool) external payable onlyOwner { + function setPoolsToSend(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); s_poolsToDistribute.push(IPool.Pools({chainSelector: _chainSelector, poolAddress: _pool})); s_poolToSendTo[_chainSelector] = _pool; emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); + + if(isRebalance == true) { + //send through functions? + //_chainSelector / s_poolsToDistribute.length +1 (ParentPool included) + // 1. functions query balance + // 2. divide balance by number of pools left + // 3. Trigger the transfer in each chain + + // bytes[] memory args = new bytes[](4); + // args[0] = abi.encodePacked(s_hashSum); + // args[1] = abi.encodePacked(s_ethersHashSum); + // args[2] = abi.encodePacked(_chainSelector); + // args[3] = abi.encodePacked(s_poolsToDistribute.length + 1); + + // bytes32 requestId = _sendRequest(args, REBALANCE_JS_CODE); + + // s_requests[requestId] = CLFRebalance({ + + // }); + } } /** * @notice Function to set the Cap of the Master pool. * @param _newCap The new Cap of the pool */ - function setPoolCap(uint256 _newCap) external payable onlyOwner { + function setPoolCap(uint256 _newCap) external payable isProxy onlyOwner { s_maxDeposit = _newCap; emit ParentPool_MasterPoolCapUpdated(_newCap); } - function setDonHostedSecretsSlotId(uint8 _slotId) external payable onlyOwner { + function setDonHostedSecretsSlotId(uint8 _slotId) external payable isProxy onlyOwner { s_donHostedSecretsSlotId = _slotId; } - function setDonHostedSecretsVersion(uint64 _version) external payable onlyOwner { + function setDonHostedSecretsVersion(uint64 _version) external payable isProxy onlyOwner { s_donHostedSecretsVersion = _version; } - function setHashSum(bytes32 _hashSum) external payable onlyOwner { + function setHashSum(bytes32 _hashSum) external payable isProxy onlyOwner { s_hashSum = _hashSum; } - function setEthersHashSum(bytes32 _ethersHashSum) external payable onlyOwner { + function setEthersHashSum(bytes32 _ethersHashSum) external payable isProxy onlyOwner { s_ethersHashSum = _ethersHashSum; } @@ -379,7 +405,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice Function to remove Cross-chain address disapproving transfers * @param _chainSelector the CCIP chainSelector for the specific chain */ - function removePoolsFromListOfSenders(uint64 _chainSelector) external payable onlyOwner { + function removePoolsFromListOfSenders(uint64 _chainSelector) external payable isProxy onlyOwner { address removedPool; for (uint256 i; i < s_poolsToDistribute.length; ) { if (s_poolsToDistribute[i].chainSelector == _chainSelector) { @@ -392,11 +418,31 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { ++i; } } + emit ParentPool_ChainAndAddressRemoved(_chainSelector); //send through functions? - //_chainSelector / removedPool / s_poolsToDistribute.length +1 (ParentPool included) - // functions query balance, divide by number of pools left and trigger the transfer in each chain + //_chainSelector / removedPool / s_poolsToDistribute.length +1 (ParentPool included) + // 1. functions query balance [balanceOf() + s_loansInUse] from deletedPool + // 2. divide balance by number of pools left [being sent as args] + // 3. Trigger the transfer sending money to other pools + //-> Ideally one at time nested in only one CLF call. + // Why is that? Because one transfer call can fail and will not affect others. + //Q1. It's possible for this JS code to hold the chainSelectors for every chain and compare to the one is deleted? + //Q2. The one being deleted don + + // bytes[] memory args = new bytes[](5); + // args[0] = abi.encodePacked(s_hashSum); + // args[1] = abi.encodePacked(s_ethersHashSum); + // args[2] = abi.encodePacked(_chainSelector); + // args[3] = abi.encodePacked(removedPool); + // args[4] = abi.encodePacked(s_poolsToDistribute.length + 1); + + // bytes32 requestId = _sendRequest(args, REBALANCE_JS_CODE); + + // s_requests[requestId] = CLFRebalance({ + + // }); } //////////////// @@ -710,7 +756,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice Function to check if a caller address is an allowed messenger * @param _messenger the address of the caller */ - function isMessenger(address _messenger) internal pure returns (bool isMessenger) { + function isMessenger(address _messenger) internal pure returns (bool _isMessenger) { address[] memory messengers = new address[](4); //Number of messengers. To define. messengers[0] = 0x11111003F38DfB073C6FeE2F5B35A0e57dAc4715; messengers[1] = 0x05CF0be5cAE993b4d7B70D691e063f1E0abeD267; From 0c33e209d1031fc1f53ab95968df9279d20711a0 Mon Sep 17 00:00:00 2001 From: Barba Date: Sat, 13 Jul 2024 17:26:30 -0300 Subject: [PATCH 05/17] Optimize Add&Remove pool system --- .../UnitTests/ParentPool.t.sol | 22 ++- .../hardhat/contracts/ConceroChildPool.sol | 129 +++++++++++---- .../hardhat/contracts/Interfaces/IPool.sol | 6 - .../contracts/Libraries/ChildStorage.sol | 3 + .../contracts/Libraries/ParentStorage.sol | 2 +- packages/hardhat/contracts/ParentPool.sol | 148 ++++++++---------- 6 files changed, 187 insertions(+), 123 deletions(-) diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol index 0c95a820b..ebdde6e02 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol @@ -110,7 +110,7 @@ contract ParentPoolTest is Test { /////////////////////////////////////////////////////////////// ///setConceroContractSender/// event ParentPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256); - function test_setParentPool() public { + function test_setConceroContractSender() public { vm.prank(Tester); vm.expectEmit(); emit ParentPool_ConceroSendersUpdated(mockDestinationChainSelector, address(mockChildPoolAddress), 1); @@ -130,9 +130,9 @@ contract ParentPoolTest is Test { wMaster.setConceroContractSender(mockDestinationChainSelector, address(0), 1); } - //setParentPoolReceiver/// + //setPoolsToSend/// event ParentPool_PoolReceiverUpdated(uint64 chainSelector, address contractAddress); - function test_setParentPoolReceiver() public { + function test_setPoolsToSend() public { vm.prank(Tester); vm.expectEmit(); emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); @@ -141,12 +141,16 @@ contract ParentPoolTest is Test { assertEq(wMaster.s_poolToSendTo(mockDestinationChainSelector), address(mockChildPoolAddress)); } - function test_revertSetParentPoolReceiver() public { + event ParentPool_RedistributionStarted(bytes32); + function test_revertSetPoolsToSend() public { vm.expectRevert(abi.encodeWithSelector(ParentPool_NotContractOwner.selector)); wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); + vm.expectEmit(); + emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); + emit ParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled. + wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), true); vm.prank(Tester); vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); @@ -157,6 +161,13 @@ contract ParentPoolTest is Test { wMaster.setPoolsToSend(mockDestinationChainSelector, address(0), false); } + function test_distributeLiquidity() public { + uint64 fakeChainSelector = 15165481213213213; + vm.prank(Messenger); + vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); + wMaster.distributeLiquidity(fakeChainSelector, 10*10**6); + } + ///orchestratorLoan/// error ParentPool_ItsNotOrchestrator(address); error ParentPool_InsufficientBalance(); @@ -238,6 +249,7 @@ contract ParentPoolTest is Test { vm.prank(Tester); vm.expectEmit(); emit ParentPool_ChainAndAddressRemoved(mockDestinationChainSelector); + emit ParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled wMaster.removePoolsFromListOfSenders(mockDestinationChainSelector); } } diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index 3089850a7..4e312620e 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -10,6 +10,7 @@ import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/shared/interface import {ChildStorage} from "contracts/Libraries/ChildStorage.sol"; import {IStorage} from "./Interfaces/IStorage.sol"; import {IOrchestrator} from "./Interfaces/IOrchestrator.sol"; +import {IPool} from "contracts/Interfaces/IPool.sol"; //////////////////////////////////////////////////////// //////////////////////// ERRORS //////////////////////// @@ -30,6 +31,8 @@ error ConceroChildPool_NotMessenger(address caller); error ConceroChildPool_NotContractOwner(); ///@notice error emitted when the CCIP message sender is not allowed. error ConceroChildPool_SenderNotAllowed(address sender); +///@notice error emitted if the array is empty. +error ConceroChildPool_ThereIsNoPoolToDistribute(); contract ConceroChildPool is CCIPReceiver, ChildStorage { using SafeERC20 for IERC20; @@ -72,6 +75,8 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { event ConceroChildPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256 isAllowed); ///@notice event emitted when a new pool is added event ConceroChildPool_PoolReceiverUpdated(uint64 chainSelector, address pool); + ///@notice event emitted when a pool is removed + event ConceroChildPool_ChainAndAddressRemoved(uint64 chainSelector); /////////////// ///MODIFIERS/// @@ -134,38 +139,44 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { //////////////////////// /** - * @notice Function to Distribute Liquidity across Concero Pools and process withdrawals - * @param _liquidityProviderAddress The liquidity provider that requested Withdraw. If it's a rebalance, it will be address(0) - * @param _amount amount of the token to be sent - * @dev This function will sent the address of the user as data. This address will be used to update the mapping on MasterPool. - */ - function ccipSendToPool(uint64 _chainSelector, address _liquidityProviderAddress, uint256 _amount) external onlyMessenger isProxy returns (bytes32 messageId) { - if (_amount > i_USDC.balanceOf(address(this))) revert ConceroChildPool_InsufficientBalance(); - - Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); - - Client.EVMTokenAmount memory tokenAmount = Client.EVMTokenAmount({token: address(i_USDC), amount: _amount}); - - tokenAmounts[0] = tokenAmount; - - Client.EVM2AnyMessage memory evm2AnyMessage = Client.EVM2AnyMessage({ - receiver: abi.encode(s_poolToSendTo[_chainSelector]), - data: abi.encode(_liquidityProviderAddress, address(0), 0), //0== lp fee. It will always be zero because here we are only processing withdraws - tokenAmounts: tokenAmounts, - extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 300_000})), - feeToken: address(i_linkToken) - }); - - uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); + * @notice Function called by Messenger process withdraw calls + * @param _chainSelector The destination chain selector will always be from Parent Pool + * @param _liquidityProvider the LP that requested withdraw. + * @param _amountToSend the amount to redistribute between pools. + */ + function ccipSendToPool(uint64 _chainSelector, address _liquidityProvider, uint256 _amountToSend) external isProxy onlyMessenger { + if (s_poolToSendTo[_chainSelector] == address(0)) revert ConceroChildPool_InvalidAddress(); + _ccipSend(_chainSelector, _liquidityProvider, _amountToSend); + } - if (fees > i_linkToken.balanceOf(address(this))) revert ConceroChildPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); + /** + * @notice Function called by Messenger to send USDC to a recently added pool. + * @param _chainSelector The chain selector of the new pool + * @param _amountToSend the amount to redistribute between pools. + */ + function distributeLiquidity(uint64 _chainSelector, uint256 _amountToSend) external isProxy onlyMessenger { + if (s_poolToSendTo[_chainSelector] == address(0)) revert ConceroChildPool_InvalidAddress(); + _ccipSend(_chainSelector, address(0), _amountToSend); + } - i_USDC.approve(i_ccipRouter, _amount); - i_linkToken.approve(i_ccipRouter, fees); + /** + * @notice helper function to remove and distribute liquidity when a pool is removed. + * @dev this functions should be called only if there is no transaction being processed + * @dev If Orchestrator took a loan and the money didn't rebalance yet, it will be left behind. + */ + function liquidatePool() external isProxy onlyMessenger { + uint256 numberOfPools = s_poolsToDistribute.length; + if (numberOfPools < ALLOWED) revert ConceroChildPool_ThereIsNoPoolToDistribute(); - emit ConceroChildPool_MessageSent(messageId, _chainSelector, s_poolToSendTo[_chainSelector], address(i_linkToken), fees); + uint256 amountToSentToEachPool = (i_USDC.balanceOf(address(this)) / numberOfPools) - 1; - messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); + for (uint256 i; i < numberOfPools; ) { + //This is a function to deal with adding&removing pools. So, the second param will always be address(0) + _ccipSend(s_poolsToDistribute[i], address(0), amountToSentToEachPool); + unchecked { + ++i; + } + } } /** @@ -200,7 +211,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @dev it's payable to save some gas. * @dev this functions is used on ConceroPool.sol */ - function setConceroContractSender(uint64 _chainSelector, address _contractAddress, uint256 _isAllowed) external payable onlyOwner { + function setConceroContractSender(uint64 _chainSelector, address _contractAddress, uint256 _isAllowed) external payable isProxy onlyOwner { if (_contractAddress == address(0)) revert ConceroChildPool_InvalidAddress(); s_contractsToReceiveFrom[_chainSelector][_contractAddress] = _isAllowed; @@ -213,16 +224,36 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @param _pool address of the Cross-chain ConceroPool contract * @dev only owner can call it * @dev it's payable to save some gas. - * @dev this functions is used on ConceroPool.sol */ - function setPoolsToSend(uint64 _chainSelector, address _pool) external payable onlyOwner { + function setPoolsToSend(uint64 _chainSelector, address _pool) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroChildPool_InvalidAddress(); + s_poolsToDistribute.push(_chainSelector); s_poolToSendTo[_chainSelector] = _pool; emit ConceroChildPool_PoolReceiverUpdated(_chainSelector, _pool); } + /** + * @notice Function to remove Cross-chain address disapproving transfers + * @param _chainSelector the CCIP chainSelector for the specific chain + */ + function removePoolsFromListOfSenders(uint64 _chainSelector) external payable isProxy onlyOwner { + + for (uint256 i; i < s_poolsToDistribute.length; ) { + if (s_poolsToDistribute[i] == _chainSelector) { + s_poolsToDistribute[i] = s_poolsToDistribute[s_poolsToDistribute.length - 1]; + s_poolsToDistribute.pop(); + delete s_poolToSendTo[_chainSelector]; + } + unchecked { + ++i; + } + } + + emit ConceroChildPool_ChainAndAddressRemoved(_chainSelector); + } + //////////////// /// INTERNAL /// //////////////// @@ -260,6 +291,42 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { ); } + /** + * @notice Function to Distribute Liquidity across Concero Pools and process withdrawals + * @param _liquidityProviderAddress The liquidity provider that requested Withdraw. If it's a rebalance, it will be address(0) + * @param _amount amount of the token to be sent + * @dev This function will sent the address of the user as data. This address will be used to update the mapping on ParentPool. + * @dev when processing withdrawals, the _chainSelector will always be the index 0 of s_poolsToDistribute + */ + function _ccipSend(uint64 _chainSelector, address _liquidityProviderAddress, uint256 _amount) internal onlyMessenger isProxy returns (bytes32 messageId) { + if (_amount > i_USDC.balanceOf(address(this))) revert ConceroChildPool_InsufficientBalance(); + + Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); + + Client.EVMTokenAmount memory tokenAmount = Client.EVMTokenAmount({token: address(i_USDC), amount: _amount}); + + tokenAmounts[0] = tokenAmount; + + Client.EVM2AnyMessage memory evm2AnyMessage = Client.EVM2AnyMessage({ + receiver: abi.encode(s_poolToSendTo[_chainSelector]), + data: abi.encode(_liquidityProviderAddress, address(0), 0), //0== lp fee. It will always be zero because here we are only processing withdraws + tokenAmounts: tokenAmounts, + extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 300_000})), + feeToken: address(i_linkToken) + }); + + uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); + + if (fees > i_linkToken.balanceOf(address(this))) revert ConceroChildPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); + + i_USDC.approve(i_ccipRouter, _amount); + i_linkToken.approve(i_ccipRouter, fees); + + emit ConceroChildPool_MessageSent(messageId, _chainSelector, s_poolToSendTo[_chainSelector], address(i_linkToken), fees); + + messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); + } + /////////////////////////// ///VIEW & PURE FUNCTIONS/// /////////////////////////// diff --git a/packages/hardhat/contracts/Interfaces/IPool.sol b/packages/hardhat/contracts/Interfaces/IPool.sol index 28542de5e..36aa12ea8 100644 --- a/packages/hardhat/contracts/Interfaces/IPool.sol +++ b/packages/hardhat/contracts/Interfaces/IPool.sol @@ -15,12 +15,6 @@ interface IPool { uint256 deadline; } - ///@notice `ccipSend` to distribute liquidity - struct Pools { - uint64 chainSelector; - address poolAddress; - } - ///@notice Struct to track Functions Requests Type enum RequestType { GetTotalUSDC, //Deposits diff --git a/packages/hardhat/contracts/Libraries/ChildStorage.sol b/packages/hardhat/contracts/Libraries/ChildStorage.sol index b9352c530..022251d06 100644 --- a/packages/hardhat/contracts/Libraries/ChildStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildStorage.sol @@ -13,6 +13,9 @@ contract ChildStorage { ///////////// ///STORAGE/// ///////////// + ///@notice array of Pools to receive Liquidity through `ccipSend` function + uint64[] s_poolsToDistribute; + ///@notice Mapping to keep track of allowed pool senders mapping(uint64 chainSelector => mapping(address conceroContract => uint256)) public s_contractsToReceiveFrom; mapping(uint64 chainSelector => address pools) public s_poolToSendTo; diff --git a/packages/hardhat/contracts/Libraries/ParentStorage.sol b/packages/hardhat/contracts/Libraries/ParentStorage.sol index dd5411664..fc971a39b 100644 --- a/packages/hardhat/contracts/Libraries/ParentStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentStorage.sol @@ -29,7 +29,7 @@ contract ParentStorage { ///STORAGE/// ///////////// ///@notice array of Pools to receive Liquidity through `ccipSend` function - IPool.Pools[] s_poolsToDistribute; + uint64[] s_poolsToDistribute; ///@notice Mapping to keep track of allowed pool receiver mapping(uint64 chainSelector => address pool) public s_poolToSendTo; diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 0b36a6b4a..727e588b1 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -129,6 +129,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { event ParentPool_ConceroContractUpdated(address concero); ///@notice event emitted when a contract is removed from the distribution array event ParentPool_ChainAndAddressRemoved(uint64 _chainSelector); + ///@notice event emitted when a pool is removed and the redistribution process start + event ParentPool_RedistributionStarted(bytes32 requestId); ///@notice event emitted when the MasterPool Cap is increased event ParentPool_MasterPoolCapUpdated(uint256 _newCap); @@ -226,7 +228,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { uint256 numberOfPools = s_poolsToDistribute.length; - if (numberOfPools < 1) revert ParentPool_ThereIsNoPoolToDistribute(); + if (numberOfPools < ALLOWED) revert ParentPool_ThereIsNoPoolToDistribute(); // uint256 depositFee = _calculateDepositTransactionFee(_usdcAmount); // uint256 depositMinusFee = _usdcAmount - _convertToUSDCTokenDecimals(depositFee); @@ -251,7 +253,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { i_USDC.safeTransferFrom(msg.sender, address(this), _usdcAmount); // i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(depositFee)); - _distributeLiquidity(numberOfPools, amountToDistribute); + _distributeLiquidity(amountToDistribute); } /** @@ -308,15 +310,13 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { } /** - * @notice Function called by Messenger to re-balance USDC between pools after and addition or exclusion - * @param _chainSelector the chain selector to be sent - * @param _notUsedHere in parent pool, is always address(0). We maintain it here so we can standardize the function to CLF calls. + * @notice Function called by Messenger to send USDC to a recently added pool. + * @param _chainSelector The chain selector of the new pool * @param _amountToSend the amount to redistribute between pools. */ - function ccipSendToPool(uint64 _chainSelector, address _notUsedHere, uint256 _amountToSend) external isProxy onlyMessenger { - if(s_poolToSendTo[_chainSelector] == address(0)) revert ParentPool_InvalidAddress(); - - _ccipSend(_chainSelector, s_poolToSendTo[_chainSelector], _amountToSend); + function distributeLiquidity(uint64 _chainSelector, uint256 _amountToSend) external isProxy onlyMessenger { + if (s_poolToSendTo[_chainSelector] == address(0)) revert ParentPool_InvalidAddress(); + _ccipSend(_chainSelector, _amountToSend); } /////////////////////// @@ -338,43 +338,6 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { emit ParentPool_ConceroSendersUpdated(_chainSelector, _contractAddress, _isAllowed); } - /** - * @notice function to manage the Cross-chain ConceroPool contracts - * @param _chainSelector chain identifications - * @param _pool address of the Cross-chain ConceroPool contract - * @dev only owner can call it - * @dev it's payable to save some gas. - * @dev this functions is used on ConceroPool.sol - */ - function setPoolsToSend(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { - if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); - s_poolsToDistribute.push(IPool.Pools({chainSelector: _chainSelector, poolAddress: _pool})); - - s_poolToSendTo[_chainSelector] = _pool; - - emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); - - if(isRebalance == true) { - //send through functions? - //_chainSelector / s_poolsToDistribute.length +1 (ParentPool included) - // 1. functions query balance - // 2. divide balance by number of pools left - // 3. Trigger the transfer in each chain - - // bytes[] memory args = new bytes[](4); - // args[0] = abi.encodePacked(s_hashSum); - // args[1] = abi.encodePacked(s_ethersHashSum); - // args[2] = abi.encodePacked(_chainSelector); - // args[3] = abi.encodePacked(s_poolsToDistribute.length + 1); - - // bytes32 requestId = _sendRequest(args, REBALANCE_JS_CODE); - - // s_requests[requestId] = CLFRebalance({ - - // }); - } - } - /** * @notice Function to set the Cap of the Master pool. * @param _newCap The new Cap of the pool @@ -401,6 +364,43 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { s_ethersHashSum = _ethersHashSum; } + /** + * @notice function to manage the Cross-chain ConceroPool contracts + * @param _chainSelector chain identifications + * @param _pool address of the Cross-chain ConceroPool contract + * @dev only owner can call it + * @dev it's payable to save some gas. + * @dev this functions is used on ConceroPool.sol + */ + function setPoolsToSend(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { + if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); + + s_poolsToDistribute.push(_chainSelector); + s_poolToSendTo[_chainSelector] = _pool; + + emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); + + if(isRebalance == true) { + //send through functions? + // 1. functions query balance from every pool(Child+Parent) using (balanceOf+s_loansInUse) + // 2. divide balance by the number of pools + parent + // 3. Trigger the transfer in each chain. Inputs: chainSelector of the new chain. Amount to send. + + bytes[] memory args = new bytes[](4); + args[0] = abi.encodePacked(s_hashSum); + args[1] = abi.encodePacked(s_ethersHashSum); + args[2] = abi.encodePacked(_chainSelector); + args[3] = abi.encodePacked(s_poolsToDistribute.length + 1); + + bytes32 requestId/* = _sendRequest(args, REBALANCE_JS_CODE)*/; + + // s_requests[requestId] = CLFRebalance({ + // }); + + emit ParentPool_RedistributionStarted(requestId); + } + } + /** * @notice Function to remove Cross-chain address disapproving transfers * @param _chainSelector the CCIP chainSelector for the specific chain @@ -408,7 +408,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { function removePoolsFromListOfSenders(uint64 _chainSelector) external payable isProxy onlyOwner { address removedPool; for (uint256 i; i < s_poolsToDistribute.length; ) { - if (s_poolsToDistribute[i].chainSelector == _chainSelector) { + if (s_poolsToDistribute[i] == _chainSelector) { removedPool = s_poolToSendTo[_chainSelector]; s_poolsToDistribute[i] = s_poolsToDistribute[s_poolsToDistribute.length - 1]; s_poolsToDistribute.pop(); @@ -422,27 +422,18 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { emit ParentPool_ChainAndAddressRemoved(_chainSelector); //send through functions? - //_chainSelector / removedPool / s_poolsToDistribute.length +1 (ParentPool included) - // 1. functions query balance [balanceOf() + s_loansInUse] from deletedPool - // 2. divide balance by number of pools left [being sent as args] - // 3. Trigger the transfer sending money to other pools - //-> Ideally one at time nested in only one CLF call. - // Why is that? Because one transfer call can fail and will not affect others. - //Q1. It's possible for this JS code to hold the chainSelectors for every chain and compare to the one is deleted? - //Q2. The one being deleted don - - // bytes[] memory args = new bytes[](5); - // args[0] = abi.encodePacked(s_hashSum); - // args[1] = abi.encodePacked(s_ethersHashSum); - // args[2] = abi.encodePacked(_chainSelector); - // args[3] = abi.encodePacked(removedPool); - // args[4] = abi.encodePacked(s_poolsToDistribute.length + 1); - - // bytes32 requestId = _sendRequest(args, REBALANCE_JS_CODE); + // 1. Trigger the liquidatePool functions to transfer money equally to other pools - // s_requests[requestId] = CLFRebalance({ + bytes[] memory args = new bytes[](5); + args[0] = abi.encodePacked(s_hashSum); + args[1] = abi.encodePacked(s_ethersHashSum); + + bytes32 requestId /*= _sendRequest(args, REBALANCE_JS_CODE)*/; + // s_requests[requestId] = CLFRebalance({ // }); + + emit ParentPool_RedistributionStarted(requestId); } //////////////// @@ -495,14 +486,13 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { /** * @notice helper function to distribute liquidity after LP deposits. - * @param _numberOfPools number of pools to receive liquidity * @param _amountToDistribute amount of USDC should be distributed to the pools. */ - function _distributeLiquidity(uint256 _numberOfPools, uint256 _amountToDistribute) internal { - for (uint256 i; i < _numberOfPools; ) { - IPool.Pools memory pool = s_poolsToDistribute[i]; + function _distributeLiquidity(uint256 _amountToDistribute) internal { + uint256 numberOfPools = s_poolsToDistribute.length; + for (uint256 i; i < numberOfPools; ) { - _ccipSend(pool.chainSelector, pool.poolAddress, _amountToDistribute); + _ccipSend(s_poolsToDistribute[i], _amountToDistribute); unchecked { ++i; @@ -514,8 +504,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice Function to distribute funds automatically right after LP deposits into the pool * @dev this function will only be called internally. */ - function _ccipSend(uint64 _chainSelector, address _poolAddress, uint256 _amountToDistribute) internal returns (bytes32 messageId) { - Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToDistribute, _poolAddress); + function _ccipSend(uint64 _chainSelector, uint256 _amountToDistribute) internal returns (bytes32 messageId) { + Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(_chainSelector, address(i_USDC), _amountToDistribute); uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); @@ -526,16 +516,16 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); - emit ParentPool_MessageSent(messageId, _chainSelector, _poolAddress, address(i_linkToken), fees); + emit ParentPool_MessageSent(messageId, _chainSelector, s_poolToSendTo[_chainSelector], address(i_linkToken), fees); } - function _buildCCIPMessage(address _token, uint256 _amount, address _poolAddress) internal view returns (Client.EVM2AnyMessage memory) { + function _buildCCIPMessage(uint64 _chainSelector, address _token, uint256 _amount) internal view returns (Client.EVM2AnyMessage memory) { Client.EVMTokenAmount[] memory tokenAmounts = new Client.EVMTokenAmount[](1); tokenAmounts[0] = Client.EVMTokenAmount({token: _token, amount: _amount}); return Client.EVM2AnyMessage({ - receiver: abi.encode(_poolAddress), + receiver: abi.encode(s_poolToSendTo[_chainSelector]), data: abi.encode(address(0), address(0), 0), //Here the 1° address is (0) because this is the Parent Pool and we never send to withdraw in another place. tokenAmounts: tokenAmounts, extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 350_000})), @@ -660,11 +650,10 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // uint256 lastBaseGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); // for(uint256 i; i < numberOfPools; ){ - // IPool.Pools memory pool = s_poolsToDistribute[i]; - // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), pool.poolAddress); + // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), s_poolToSendTo[s_poolsToDistribute[i]]); // //Link cost for all transactions - // costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(pool.chainSelector, evm2AnyMessage); + // costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(s_poolsToDistribute[i], evm2AnyMessage); // unchecked { // ++i; // } @@ -688,13 +677,12 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // uint256 costOfCCIPSendToPoolExecution; // for(uint256 i; i < numberOfPools; ){ - // IPool.Pools memory pool = s_poolsToDistribute[i]; // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToReceive, address(this)); // //Link cost for all transactions // costOfLinkForLiquidityWithdraw += IRouterClient(i_ccipRouter).getFee(BASE_CHAIN_SELECTOR, evm2AnyMessage); //here the chainSelector must be Base's? // //USDC costs for all writing from the above transactions - // costOfCCIPSendToPoolExecution += Orchestrator(i_infraProxy).s_lastGasPrices(pool.chainSelector) * WRITE_FUNCTIONS_COST; + // costOfCCIPSendToPoolExecution += Orchestrator(i_infraProxy).s_lastGasPrices(s_poolsToDistribute[i]) * WRITE_FUNCTIONS_COST; // unchecked { // ++i; // } From eb91f92394d338dd8a3f2356b6fd09e4ed9692ca Mon Sep 17 00:00:00 2001 From: Barba Date: Sat, 13 Jul 2024 18:15:03 -0300 Subject: [PATCH 06/17] Improve inline comments --- packages/hardhat/contracts/ParentPool.sol | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 727e588b1..040061960 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -381,10 +381,11 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); if(isRebalance == true) { - //send through functions? - // 1. functions query balance from every pool(Child+Parent) using (balanceOf+s_loansInUse) - // 2. divide balance by the number of pools + parent - // 3. Trigger the transfer in each chain. Inputs: chainSelector of the new chain. Amount to send. + //balancePool = Query balance from ChildPools & ParentPool + //totalBalance = balancePool1 + balancePool2 + balancePool3 + //expectedBalance = totalBalance / newNumberOfPools + //amountToDistribute = balancePool - expectedBalance (for each, besides the new one) + //trigger distributeLiquidity(_chainSelector, _amountToDistribute) bytes[] memory args = new bytes[](4); args[0] = abi.encodePacked(s_hashSum); @@ -424,9 +425,11 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { //send through functions? // 1. Trigger the liquidatePool functions to transfer money equally to other pools - bytes[] memory args = new bytes[](5); + bytes[] memory args = new bytes[](4); args[0] = abi.encodePacked(s_hashSum); args[1] = abi.encodePacked(s_ethersHashSum); + args[2] = abi.encodePacked(_chainSelector); + args[3] = abi.encodePacked(removedPool); bytes32 requestId /*= _sendRequest(args, REBALANCE_JS_CODE)*/; From 52c56e7b5848f0e7c827c882cd8d6798eda6ffc5 Mon Sep 17 00:00:00 2001 From: Oleg Kirillovich Date: Sun, 14 Jul 2024 15:20:17 +0100 Subject: [PATCH 07/17] todos --- .../hardhat/contracts/Libraries/ChildStorage.sol | 1 + .../hardhat/contracts/Libraries/ParentStorage.sol | 5 +++-- packages/hardhat/contracts/ParentPool.sol | 14 +++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/hardhat/contracts/Libraries/ChildStorage.sol b/packages/hardhat/contracts/Libraries/ChildStorage.sol index 022251d06..99b4ccdac 100644 --- a/packages/hardhat/contracts/Libraries/ChildStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildStorage.sol @@ -1,6 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.20; +// todo: ChildPoolStorage contract ChildStorage { ///////////////////// ///STATE VARIABLES/// diff --git a/packages/hardhat/contracts/Libraries/ParentStorage.sol b/packages/hardhat/contracts/Libraries/ParentStorage.sol index fc971a39b..a2f428f3a 100644 --- a/packages/hardhat/contracts/Libraries/ParentStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentStorage.sol @@ -3,11 +3,12 @@ pragma solidity 0.8.20; import {IPool} from "contracts/Interfaces/IPool.sol"; -contract ParentStorage { +// todo: ParentPoolStorage +contract ParentStorage { ///////////////////// ///STATE VARIABLES/// ///////////////////// - + ///@notice variable to store the max value that can be deposited on this pool uint256 public s_maxDeposit; ///@notice variable to store the amount that will be temporary used by Chainlink Functions diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 040061960..1007d6b93 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -47,6 +47,7 @@ error ParentPool_CallerIsNotTheProxy(address caller); ///@notice error emitted when the caller is not the owner error ParentPool_NotContractOwner(); +//todo: ConceroParentPool contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { /////////////////////// ///TYPE DECLARATIONS/// @@ -372,6 +373,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev it's payable to save some gas. * @dev this functions is used on ConceroPool.sol */ + + //todo: setPools function setPoolsToSend(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); @@ -380,7 +383,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); - if(isRebalance == true) { + if (isRebalance == true) { //balancePool = Query balance from ChildPools & ParentPool //totalBalance = balancePool1 + balancePool2 + balancePool3 //expectedBalance = totalBalance / newNumberOfPools @@ -393,7 +396,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { args[2] = abi.encodePacked(_chainSelector); args[3] = abi.encodePacked(s_poolsToDistribute.length + 1); - bytes32 requestId/* = _sendRequest(args, REBALANCE_JS_CODE)*/; + //todo: @nikita pools have to track requests in order to prevent 4 nodes triggering a rebalance on the same pool + bytes32 requestId /* = _sendRequest(args, REBALANCE_JS_CODE)*/; // s_requests[requestId] = CLFRebalance({ // }); @@ -406,6 +410,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice Function to remove Cross-chain address disapproving transfers * @param _chainSelector the CCIP chainSelector for the specific chain */ + //todo: removePools function removePoolsFromListOfSenders(uint64 _chainSelector) external payable isProxy onlyOwner { address removedPool; for (uint256 i; i < s_poolsToDistribute.length; ) { @@ -423,7 +428,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { emit ParentPool_ChainAndAddressRemoved(_chainSelector); //send through functions? - // 1. Trigger the liquidatePool functions to transfer money equally to other pools + // 1. Trigger the liquidatePool functions to transfer money equally to other pools bytes[] memory args = new bytes[](4); args[0] = abi.encodePacked(s_hashSum); @@ -431,6 +436,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { args[2] = abi.encodePacked(_chainSelector); args[3] = abi.encodePacked(removedPool); + //todo: @nikita pools have to track requests in order to prevent 4 nodes triggering a liquidation on the same pool bytes32 requestId /*= _sendRequest(args, REBALANCE_JS_CODE)*/; // s_requests[requestId] = CLFRebalance({ @@ -494,7 +500,6 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { function _distributeLiquidity(uint256 _amountToDistribute) internal { uint256 numberOfPools = s_poolsToDistribute.length; for (uint256 i; i < numberOfPools; ) { - _ccipSend(s_poolsToDistribute[i], _amountToDistribute); unchecked { @@ -764,5 +769,4 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { } return false; } - } From aac3235529df097f5f2d35a0ea83fec41f438335 Mon Sep 17 00:00:00 2001 From: Barba Date: Sun, 14 Jul 2024 11:34:07 -0300 Subject: [PATCH 08/17] Update namings. Add Natspec --- .../IntegrationTests/InfraIntegration.t.sol | 2 +- .../MainnetFork/ProtocolMainnet.t.sol | 2 +- .../TestnetFork/ProtocolTestnet.t.sol | 5 ++-- .../UnitTests/ParentPool.t.sol | 24 +++++++++---------- .../hardhat/contracts/ConceroChildPool.sol | 4 ++-- .../contracts/Libraries/ChildStorage.sol | 1 + .../contracts/Libraries/ParentStorage.sol | 8 +++---- .../hardhat/contracts/Libraries/Storage.sol | 2 +- packages/hardhat/contracts/ParentPool.sol | 7 ++---- .../deployPool/setParentPoolVariables.ts | 18 +++++++------- 10 files changed, 36 insertions(+), 37 deletions(-) diff --git a/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol b/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol index 4a98bf5b6..cd70f5b41 100644 --- a/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol @@ -408,7 +408,7 @@ contract InfraIntegration is Test { //Parent Pool wMaster.setConceroContractSender(localChainSelector, address(wChild), 1); - wMaster.setPoolsToSend(localChainSelector, address(wChild), false); + wMaster.setPools(localChainSelector, address(wChild), false); //Child Pool wChild.setConceroContractSender(localChainSelector, address(wMaster), 1); diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index 8aed23074..c7e5a89f6 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -474,7 +474,7 @@ contract ProtocolMainnet is Test { //====== Setters ///== Pools vm.startPrank(Tester); - wMaster.setPoolsToSend(arbChainSelector, address(childProxy), false); + wMaster.setPools(arbChainSelector, address(childProxy), false); assertEq(wMaster.s_poolToSendTo(arbChainSelector), address(wChild)); wMaster.setConceroContractSender(arbChainSelector, address(wChild), 1); diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index 89375a0ed..a9666d074 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -432,7 +432,7 @@ contract ProtocolTestnet is Test { ///======= Pools Allowance vm.startPrank(Tester); - wMaster.setPoolsToSend(arbChainSelector, address(childProxy), false); + wMaster.setPools(arbChainSelector, address(childProxy), false); assertEq(wMaster.s_poolToSendTo(arbChainSelector), address(wChild)); wMaster.setConceroContractSender(arbChainSelector, address(wChild), 1); @@ -1097,8 +1097,9 @@ contract ProtocolTestnet is Test { vm.stopPrank(); //====== Check Receiver balance - assertEq(IERC20(ccipBnMArb).balanceOf(User), 9990000); //Amount - fee = 9831494 + // assertEq(IERC20(ccipBnMArb).balanceOf(User), 9990000); //Amount - fee = 9831494 + // vm.selectFork(baseTestFork); // assertTrue(op.s_lastGasPrices(arbChainSelector) > 0); // assertTrue(op.s_latestLinkUsdcRate() > 0); // assertTrue(op.s_latestNativeUsdcRate() > 0); diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol index ebdde6e02..61977a7ed 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol @@ -130,35 +130,35 @@ contract ParentPoolTest is Test { wMaster.setConceroContractSender(mockDestinationChainSelector, address(0), 1); } - //setPoolsToSend/// + //setPools/// event ParentPool_PoolReceiverUpdated(uint64 chainSelector, address contractAddress); - function test_setPoolsToSend() public { + function test_setPools() public { vm.prank(Tester); vm.expectEmit(); emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); assertEq(wMaster.s_poolToSendTo(mockDestinationChainSelector), address(mockChildPoolAddress)); } event ParentPool_RedistributionStarted(bytes32); - function test_revertSetPoolsToSend() public { + function test_revertSetPools() public { vm.expectRevert(abi.encodeWithSelector(ParentPool_NotContractOwner.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectEmit(); emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); emit ParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled. - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), true); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), true); vm.prank(Tester); vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(0), false); + wMaster.setPools(mockDestinationChainSelector, address(0), false); } function test_distributeLiquidity() public { @@ -198,7 +198,7 @@ contract ParentPoolTest is Test { //===== Add a Fake pool vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress, false); + wMaster.setPools(mockDestinationChainSelector, mockChildPoolAddress, false); //===== Cap is Zero vm.prank(Tester); @@ -222,7 +222,7 @@ contract ParentPoolTest is Test { wMaster.depositLiquidity(allowedAmountToDeposit); vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress, false); + wMaster.setPools(mockDestinationChainSelector, mockChildPoolAddress, false); // vm.prank(Tester); // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); @@ -244,12 +244,12 @@ contract ParentPoolTest is Test { event ParentPool_ChainAndAddressRemoved(uint64 chainSelector); function test_removePoolFromArray() public { vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress), false); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectEmit(); emit ParentPool_ChainAndAddressRemoved(mockDestinationChainSelector); emit ParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled - wMaster.removePoolsFromListOfSenders(mockDestinationChainSelector); + wMaster.removePools(mockDestinationChainSelector); } } diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index 4e312620e..7d4fe3f69 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -225,7 +225,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @dev only owner can call it * @dev it's payable to save some gas. */ - function setPoolsToSend(uint64 _chainSelector, address _pool) external payable isProxy onlyOwner { + function setPools(uint64 _chainSelector, address _pool) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroChildPool_InvalidAddress(); s_poolsToDistribute.push(_chainSelector); @@ -238,7 +238,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @notice Function to remove Cross-chain address disapproving transfers * @param _chainSelector the CCIP chainSelector for the specific chain */ - function removePoolsFromListOfSenders(uint64 _chainSelector) external payable isProxy onlyOwner { + function removePools(uint64 _chainSelector) external payable isProxy onlyOwner { for (uint256 i; i < s_poolsToDistribute.length; ) { if (s_poolsToDistribute[i] == _chainSelector) { diff --git a/packages/hardhat/contracts/Libraries/ChildStorage.sol b/packages/hardhat/contracts/Libraries/ChildStorage.sol index 99b4ccdac..f352a65f6 100644 --- a/packages/hardhat/contracts/Libraries/ChildStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildStorage.sol @@ -19,5 +19,6 @@ contract ChildStorage { ///@notice Mapping to keep track of allowed pool senders mapping(uint64 chainSelector => mapping(address conceroContract => uint256)) public s_contractsToReceiveFrom; + ///@notice Mapping to keep track of valid pools to transfer in case of liquidation or rebalance mapping(uint64 chainSelector => address pools) public s_poolToSendTo; } diff --git a/packages/hardhat/contracts/Libraries/ParentStorage.sol b/packages/hardhat/contracts/Libraries/ParentStorage.sol index a2f428f3a..a1d713423 100644 --- a/packages/hardhat/contracts/Libraries/ParentStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentStorage.sol @@ -4,17 +4,17 @@ pragma solidity 0.8.20; import {IPool} from "contracts/Interfaces/IPool.sol"; // todo: ParentPoolStorage -contract ParentStorage { +contract ParentStorage { ///////////////////// ///STATE VARIABLES/// ///////////////////// ///@notice variable to store the max value that can be deposited on this pool - uint256 public s_maxDeposit; + uint256 internal s_maxDeposit; ///@notice variable to store the amount that will be temporary used by Chainlink Functions uint256 public s_loansInUse; ///@notice variable to store the amount requested in withdraws - uint256 public s_withdrawRequests; + uint256 internal s_withdrawRequests; ///@notice variable to store the Chainlink Function DON Slot ID uint8 internal s_donHostedSecretsSlotId; ///@notice variable to store the Chainlink Function DON Secret Version @@ -32,7 +32,7 @@ contract ParentStorage { ///@notice array of Pools to receive Liquidity through `ccipSend` function uint64[] s_poolsToDistribute; - ///@notice Mapping to keep track of allowed pool receiver + ///@notice Mapping to keep track of valid pools to transfer in case of liquidation or rebalance mapping(uint64 chainSelector => address pool) public s_poolToSendTo; ///@notice Mapping to keep track of allowed pool senders mapping(uint64 chainSelector => mapping(address poolAddress => uint256)) public s_contractsToReceiveFrom; diff --git a/packages/hardhat/contracts/Libraries/Storage.sol b/packages/hardhat/contracts/Libraries/Storage.sol index 090627dc0..1bf53f6d4 100644 --- a/packages/hardhat/contracts/Libraries/Storage.sol +++ b/packages/hardhat/contracts/Libraries/Storage.sol @@ -45,5 +45,5 @@ abstract contract Storage is ReentrancyGuard, IStorage { ///@notice Functions: Mapping to keep track of Chainlink Functions requests mapping(bytes32 => Request) public s_requests; ///@notice Functions: Mapping to keep track of cross-chain gas prices - mapping(uint64 chainSelector => uint256 lasGasPrice) public s_lastGasPrices; + mapping(uint64 chainSelector => uint256 lastGasPrice) public s_lastGasPrices; } diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ParentPool.sol index 1007d6b93..f37c84aa2 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ParentPool.sol @@ -373,9 +373,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev it's payable to save some gas. * @dev this functions is used on ConceroPool.sol */ - - //todo: setPools - function setPoolsToSend(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { + function setPools(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); s_poolsToDistribute.push(_chainSelector); @@ -410,8 +408,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice Function to remove Cross-chain address disapproving transfers * @param _chainSelector the CCIP chainSelector for the specific chain */ - //todo: removePools - function removePoolsFromListOfSenders(uint64 _chainSelector) external payable isProxy onlyOwner { + function removePools(uint64 _chainSelector) external payable isProxy onlyOwner { address removedPool; for (uint256 i; i < s_poolsToDistribute.length; ) { if (s_poolsToDistribute[i] == _chainSelector) { diff --git a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts index 8ecdfce92..4327171db 100644 --- a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts +++ b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts @@ -190,7 +190,7 @@ async function setConceroContractSenders(chain: CNetwork, abi: any) { } } -async function setPoolsToSend(chain: CNetwork, abi: any) { +async function setPools(chain: CNetwork, abi: any) { const { name: chainName, viemChain, url } = chain; const clients = getClients(viemChain, url); const { publicClient, account, walletClient } = clients; @@ -207,7 +207,7 @@ async function setPoolsToSend(chain: CNetwork, abi: any) { const { request: setReceiverReq } = await publicClient.simulateContract({ address: conceroPoolAddress, - functionName: "setPoolsToSend", + functionName: "setPools", args: [dstChainSelector, dstPoolAddress], abi, account, @@ -219,10 +219,10 @@ async function setPoolsToSend(chain: CNetwork, abi: any) { }); log( `Set ${chainName}:${conceroPoolAddress} receiver[${dstChainName}:${dstPoolAddress}]. Gas used: ${setReceiverGasUsed.toString()}`, - "setPoolsToSend", + "setPools", ); } catch (error) { - log(`Error ${error?.message}`, "setPoolsToSend"); + log(`Error ${error?.message}`, "setPools"); } } } @@ -267,7 +267,7 @@ async function getPendingRequest(chain: CNetwork, abi: any) { console.log(pendingRequest); } -async function removePoolsFromListOfSenders(chain: CNetwork, abi, chainSelectors: string[]) { +async function removePools(chain: CNetwork, abi, chainSelectors: string[]) { const { name: chainName, viemChain, url } = chain; const clients = getClients(viemChain, url); const { publicClient, account, walletClient } = clients; @@ -279,7 +279,7 @@ async function removePoolsFromListOfSenders(chain: CNetwork, abi, chainSelectors // const { request: deletePoolReq } = await publicClient.simulateContract({ // address: parentPoolAddress, // abi, - // functionName: "removePoolsFromListOfSenders", + // functionName: "removePools", // args: [chainSelector], // account, // viemChain, @@ -288,7 +288,7 @@ async function removePoolsFromListOfSenders(chain: CNetwork, abi, chainSelectors const deletePoolHash = await walletClient.writeContract({ address: parentPoolAddress, abi, - functionName: "removePoolsFromListOfSenders", + functionName: "removePools", args: [chainSelector], account, viemChain, @@ -316,10 +316,10 @@ export async function setParentPoolVariables(chain: CNetwork, isSetSecretsNeeded await setParentPoolSecretsSlotId(chain, ParentPoolAbi, slotId); // } - await setPoolsToSend(chain, ParentPoolAbi); + await setPools(chain, ParentPoolAbi); await setConceroContractSenders(chain, ParentPoolAbi); - // await removePoolsFromListOfSenders(chain, ParentPoolAbi, ["3478487238524512106", "5224473277236331295"]); + // await removePools(chain, ParentPoolAbi, ["3478487238524512106", "5224473277236331295"]); // await deletePendingRequest(chain, ParentPoolAbi, "0xDddDDb8a8E41C194ac6542a0Ad7bA663A72741E0"); // await deletePendingRequest(chain, ParentPoolAbi, "0x1637A2cafe89Ea6d8eCb7cC7378C023f25c892b6"); } From 1638a85f33268769cb073dc1f1817716518520a2 Mon Sep 17 00:00:00 2001 From: Barba Date: Sun, 14 Jul 2024 13:22:17 -0300 Subject: [PATCH 09/17] fix: Rename files. Update dependencies. --- packages/foundry/README.md | 4 +- packages/foundry/script/ChildPoolDeploy.s.sol | 2 - .../foundry/script/ParentPoolDeploy.s.sol | 6 +- .../script/TestnetChildPoolDeploy.s.sol | 2 - .../script/TestnetParentPoolDeploy.s.sol | 6 +- .../IntegrationTests/InfraIntegration.t.sol | 9 +- .../MainnetFork/ProtocolMainnet.t.sol | 27 ++-- .../TestnetFork/ProtocolTestnet.t.sol | 53 ++++---- .../UnitTests/ConceroChildPool.t.sol | 1 - .../Pos-Upgradeable/UnitTests/Infra.t.sol | 8 +- .../UnitTests/ParentPool.t.sol | 76 ++++++------ .../hardhat/contracts/ConceroChildPool.sol | 10 +- .../{ParentPool.sol => ConceroParentPool.sol} | 116 +++++++++--------- ...{ChildStorage.sol => ChildPoolStorage.sol} | 3 +- ...arentStorage.sol => ParentPoolStorage.sol} | 2 +- .../contracts/Proxy/ChildPoolProxy.sol | 4 +- .../contracts/Proxy/ParentPoolProxy.sol | 4 +- .../deployPool/setParentPoolVariables.ts | 4 +- packages/hardhat/test/CompleteWithdrawal.ts | 2 +- packages/hardhat/test/DepositUsdcToPool.ts | 2 +- packages/hardhat/test/WithdrawPoolUsdc.ts | 2 +- 21 files changed, 165 insertions(+), 178 deletions(-) rename packages/hardhat/contracts/{ParentPool.sol => ConceroParentPool.sol} (87%) rename packages/hardhat/contracts/Libraries/{ChildStorage.sol => ChildPoolStorage.sol} (94%) rename packages/hardhat/contracts/Libraries/{ParentStorage.sol => ParentPoolStorage.sol} (98%) diff --git a/packages/foundry/README.md b/packages/foundry/README.md index dd3cdaa86..bb592c846 100644 --- a/packages/foundry/README.md +++ b/packages/foundry/README.md @@ -75,8 +75,8 @@ Our tests don't cover Automation & Functions, once the JavaScript code is still - contracts/ConceroChildPool.sol - contracts/ConceroAutomation.sol - contracts/LPToken.sol** -- Libraries/ParentStorage.sol - it's ParentPool.sol Storage -- Libraries/ChildStorage.sol - it's ConceroChildPool.sol Storage +- Libraries/ParentPoolStorage.sol - it's ParentPool.sol Storage +- Libraries/ChildPoolStorage.sol - it's ConceroChildPool.sol Storage - Proxy/ParentPoolProxy.sol*** - Proxy/ChildPoolProxy.sol*** ``` diff --git a/packages/foundry/script/ChildPoolDeploy.s.sol b/packages/foundry/script/ChildPoolDeploy.s.sol index 67fcf574d..56fc7b336 100644 --- a/packages/foundry/script/ChildPoolDeploy.s.sol +++ b/packages/foundry/script/ChildPoolDeploy.s.sol @@ -9,7 +9,6 @@ contract ChildPoolDeploy is Script { function run( address _orchestratorProxy, - address _masterPoolProxyAddress, address _childProxy, address _link, address _ccipRouter, @@ -19,7 +18,6 @@ contract ChildPoolDeploy is Script { vm.startBroadcast(); child = new ConceroChildPool( _orchestratorProxy, - _masterPoolProxyAddress, _childProxy, _link, _ccipRouter, diff --git a/packages/foundry/script/ParentPoolDeploy.s.sol b/packages/foundry/script/ParentPoolDeploy.s.sol index 5ed35cab0..23a4eb971 100644 --- a/packages/foundry/script/ParentPoolDeploy.s.sol +++ b/packages/foundry/script/ParentPoolDeploy.s.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.20; import {Script, console2} from "../lib/forge-std/src/Script.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; contract ParentPoolDeploy is Script { @@ -19,9 +19,9 @@ contract ParentPoolDeploy is Script { address _automation, address _orchestrator, address _owner - ) public returns(ParentPool pool){ + ) public returns(ConceroParentPool pool){ vm.startBroadcast(); - pool = new ParentPool( + pool = new ConceroParentPool( _proxy, _link, _donId, diff --git a/packages/foundry/script/TestnetChildPoolDeploy.s.sol b/packages/foundry/script/TestnetChildPoolDeploy.s.sol index 7322c043a..7fc28c2df 100644 --- a/packages/foundry/script/TestnetChildPoolDeploy.s.sol +++ b/packages/foundry/script/TestnetChildPoolDeploy.s.sol @@ -7,7 +7,6 @@ import {ConceroChildPool} from "contracts/ConceroChildPool.sol"; contract TestnetChildPoolDeploy is Script { address _orchestratorProxy = address(0); - address _masterPoolProxyAddress = 0x4f4549e3349144C1eFD843f778FDcAaAbc65C9E3; address _childProxy = 0xb9b4eb0088cD3d98fF7A30a8e7DeE5eCdcC290B2; address _link = 0xE4aB69C077896252FAFBD49EFD26B5D171A32410; address _ccipRouter = 0xD3b06cEbF099CE7DA4AcCf578aaebFDBd6e88a93; @@ -18,7 +17,6 @@ contract TestnetChildPoolDeploy is Script { vm.startBroadcast(); child = new ConceroChildPool( _orchestratorProxy, - _masterPoolProxyAddress, _childProxy, _link, _ccipRouter, diff --git a/packages/foundry/script/TestnetParentPoolDeploy.s.sol b/packages/foundry/script/TestnetParentPoolDeploy.s.sol index 07f158dcb..be9eb2016 100644 --- a/packages/foundry/script/TestnetParentPoolDeploy.s.sol +++ b/packages/foundry/script/TestnetParentPoolDeploy.s.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.20; import {Script, console2} from "../lib/forge-std/src/Script.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; contract TestnetParentPoolDeploy is Script { address _proxy = 0x4f4549e3349144C1eFD843f778FDcAaAbc65C9E3; @@ -17,9 +17,9 @@ contract TestnetParentPoolDeploy is Script { address _orchestrator = address(0); address _owner = 0xd2Cb8786C0Ec3680C55C9256371F3577fE1C6A9e; - function run() public returns(ParentPool pool){ + function run() public returns(ConceroParentPool pool){ vm.startBroadcast(); - pool = new ParentPool( + pool = new ConceroParentPool( _proxy, _link, _donId, diff --git a/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol b/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol index cd70f5b41..b3d07b074 100644 --- a/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/IntegrationTests/InfraIntegration.t.sol @@ -6,7 +6,7 @@ import {Test, console} from "forge-std/Test.sol"; //Master & Infra Contracts import {DexSwap} from "contracts/DexSwap.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; import {ConceroBridge} from "contracts/ConceroBridge.sol"; import {Orchestrator} from "contracts/Orchestrator.sol"; import {LPToken} from "contracts/LPToken.sol"; @@ -69,7 +69,7 @@ contract InfraIntegration is Test { //==== Instantiate Base Contracts DexSwap public dex; - ParentPool public pool; + ConceroParentPool public pool; ConceroBridge public concero; Orchestrator public orch; Orchestrator public orchEmpty; @@ -114,7 +114,7 @@ contract InfraIntegration is Test { //==== Wrapped contract Orchestrator wInfraSrc; Orchestrator wInfraDst; - ParentPool wMaster; + ConceroParentPool wMaster; ConceroChildPool wChild; @@ -296,7 +296,7 @@ contract InfraIntegration is Test { vm.prank(ProxyOwner); proxyInterfaceMaster.upgradeToAndCall(address(pool), ""); - wMaster = ParentPool(payable(address(masterProxy))); + wMaster = ConceroParentPool(payable(address(masterProxy))); //====== Update the MINTER on the LP Token vm.prank(Tester); @@ -365,7 +365,6 @@ contract InfraIntegration is Test { child = childDeployArbitrum.run( address(proxyDst), - address(masterProxy), address(childProxy), link, ccipRouterLocalDst, diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index c7e5a89f6..f37f7b6dc 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -7,7 +7,7 @@ import {console} from "forge-std/console.sol"; //Master & Infra Contracts import {DexSwap} from "contracts/DexSwap.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; import {ConceroBridge} from "contracts/ConceroBridge.sol"; import {Orchestrator} from "contracts/Orchestrator.sol"; import {LPToken} from "contracts/LPToken.sol"; @@ -71,7 +71,7 @@ interface IWETH is IERC20 { contract ProtocolMainnet is Test { //==== Instantiate Base Contracts DexSwap public dex; - ParentPool public pool; + ConceroParentPool public pool; ConceroBridge public concero; Orchestrator public orch; Orchestrator public orchEmpty; @@ -115,7 +115,7 @@ contract ProtocolMainnet is Test { //==== Wrapped contract Orchestrator op; Orchestrator opDst; - ParentPool wMaster; + ConceroParentPool wMaster; ConceroChildPool wChild; @@ -318,7 +318,7 @@ contract ProtocolMainnet is Test { vm.prank(ProxyOwner); proxyInterfaceMaster.upgradeToAndCall(address(pool), ""); - wMaster = ParentPool(payable(address(masterProxy))); + wMaster = ConceroParentPool(payable(address(masterProxy))); //=== Base Contracts vm.makePersistent(address(proxy)); @@ -425,7 +425,6 @@ contract ProtocolMainnet is Test { child = childDeployArbitrum.run( address(proxyDst), - address(masterProxy), address(childProxy), linkArb, ccipRouterArb, @@ -1753,11 +1752,11 @@ contract ProtocolMainnet is Test { ////////////////////////////////////////////////////////////////////////////////// //This test only work with USDC Mainnet address on Storage::getToken function. - error ParentPool_AmountBelowMinimum(uint256); - error ParentPool_MaxCapReached(uint256); - event ParentPool_MasterPoolCapUpdated(uint256 _newCap); - event ParentPool_SuccessfulDeposited(address, uint256 , address); - event ParentPool_MessageSent(bytes32, uint64, address, address, uint256); + error ConceroParentPool_AmountBelowMinimum(uint256); + error ConceroParentPool_MaxCapReached(uint256); + event ConceroParentPool_MasterPoolCapUpdated(uint256 _newCap); + event ConceroParentPool_SuccessfulDeposited(address, uint256 , address); + event ConceroParentPool_MessageSent(bytes32, uint64, address, address, uint256); ///=== Functions Errors error OnlyRouterCanFulfill(); error EmptySource(); @@ -1775,14 +1774,14 @@ contract ProtocolMainnet is Test { //======= LP Deposits Low Amount of USDC on the Main Pool to revert on Min Amount vm.startPrank(LP); mUSDC.approve(address(wMaster), depositLowAmount); - vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_AmountBelowMinimum.selector, 100*10**6)); wMaster.depositLiquidity(depositLowAmount); vm.stopPrank(); //======= Increase the CAP vm.expectEmit(); vm.prank(Tester); - emit ParentPool_MasterPoolCapUpdated(50*10**6); + emit ConceroParentPool_MasterPoolCapUpdated(50*10**6); wMaster.setPoolCap(50*10**6); //======= LP Deposits enough to go through, but revert on max Cap @@ -1790,14 +1789,14 @@ contract ProtocolMainnet is Test { vm.startPrank(LP); mUSDC.approve(address(wMaster), depositEnoughAmount); - vm.expectRevert(abi.encodeWithSelector(ParentPool_MaxCapReached.selector, 50*10**6)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_MaxCapReached.selector, 50*10**6)); wMaster.depositLiquidity(depositEnoughAmount); vm.stopPrank(); //======= Increase the CAP vm.expectEmit(); vm.prank(Tester); - emit ParentPool_MasterPoolCapUpdated(1000*10**6); + emit ConceroParentPool_MasterPoolCapUpdated(1000*10**6); wMaster.setPoolCap(1000*10**6); //======= LP Deposits Successfully diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index a9666d074..05ed38662 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -6,7 +6,7 @@ import {Test, console} from "forge-std/Test.sol"; //Master & Infra Contracts import {DexSwap} from "contracts/DexSwap.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; import {ConceroBridge} from "contracts/ConceroBridge.sol"; import {Orchestrator} from "contracts/Orchestrator.sol"; import {LPToken} from "contracts/LPToken.sol"; @@ -73,7 +73,7 @@ interface IWETH is IERC20 { contract ProtocolTestnet is Test { //==== Instantiate Base Contracts DexSwap public dex; - ParentPool public pool; + ConceroParentPool public pool; ConceroBridge public concero; Orchestrator public orch; Orchestrator public orchEmpty; @@ -119,7 +119,7 @@ contract ProtocolTestnet is Test { //==== Wrapped contract Orchestrator op; Orchestrator opDst; - ParentPool wMaster; + ConceroParentPool wMaster; ConceroChildPool wChild; @@ -280,7 +280,7 @@ contract ProtocolTestnet is Test { vm.prank(ProxyOwner); proxyInterfaceMaster.upgradeToAndCall(address(pool), ""); - wMaster = ParentPool(payable(address(masterProxy))); + wMaster = ConceroParentPool(payable(address(masterProxy))); //=== Base Contracts vm.makePersistent(address(proxy)); @@ -388,7 +388,6 @@ contract ProtocolTestnet is Test { child = childDeployArbitrum.run( address(proxyDst), - address(masterProxy), address(childProxy), linkArb, ccipRouterArb, @@ -748,17 +747,17 @@ contract ProtocolTestnet is Test { ////////////////////////////////// POOL MODULE /////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// - error ParentPool_AmountBelowMinimum(uint256); - error ParentPool_MaxCapReached(uint256); - error ParentPool_AmountNotAvailableYet(uint256); - error ParentPool_InsufficientBalance(); - error ParentPool_ActiveRequestNotFulfilledYet(); - error ParentPool_CallerIsNotTheProxy(address); - event ParentPool_MasterPoolCapUpdated(uint256 _newCap); - event ParentPool_SuccessfulDeposited(address, uint256 , address); - event ParentPool_MessageSent(bytes32, uint64, address, address, uint256); - event ParentPool_WithdrawRequest(address,address,uint256); - event ParentPool_Withdrawn(address,address,uint256); + error ConceroParentPool_AmountBelowMinimum(uint256); + error ConceroParentPool_MaxCapReached(uint256); + error ConceroParentPool_AmountNotAvailableYet(uint256); + error ConceroParentPool_InsufficientBalance(); + error ConceroParentPool_ActiveRequestNotFulfilledYet(); + error ConceroParentPool_CallerIsNotTheProxy(address); + event ConceroParentPool_MasterPoolCapUpdated(uint256 _newCap); + event ConceroParentPool_SuccessfulDeposited(address, uint256 , address); + event ConceroParentPool_MessageSent(bytes32, uint64, address, address, uint256); + event ConceroParentPool_WithdrawRequest(address,address,uint256); + event ConceroParentPool_Withdrawn(address,address,uint256); ///CCIP Local doesn't allow USDC transfer in forked environment. We use ccip-BnM here. But it breaks when querying balances. function test_LiquidityProvidersDepositAndOpenARequest() public setters { vm.selectFork(baseTestFork); @@ -769,14 +768,14 @@ contract ProtocolTestnet is Test { //======= LP Deposits Low Amount of USDC on the Main Pool to revert on Min Amount vm.startPrank(LP); IERC20(ccipBnM).approve(address(wMaster), depositLowAmount); - vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_AmountBelowMinimum.selector, 100*10**6)); wMaster.depositLiquidity(depositLowAmount); vm.stopPrank(); //======= Increase the CAP vm.expectEmit(); vm.prank(Tester); - emit ParentPool_MasterPoolCapUpdated(50*10**6); + emit ConceroParentPool_MasterPoolCapUpdated(50*10**6); wMaster.setPoolCap(50*10**6); //======= LP Deposits enough to go through, but revert on max Cap @@ -784,14 +783,14 @@ contract ProtocolTestnet is Test { vm.startPrank(LP); IERC20(ccipBnM).approve(address(wMaster), depositEnoughAmount); - vm.expectRevert(abi.encodeWithSelector(ParentPool_MaxCapReached.selector, 50*10**6)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_MaxCapReached.selector, 50*10**6)); wMaster.depositLiquidity(depositEnoughAmount); vm.stopPrank(); //======= Increase the CAP vm.expectEmit(); vm.prank(Tester); - emit ParentPool_MasterPoolCapUpdated(1000*10**6); + emit ConceroParentPool_MasterPoolCapUpdated(1000*10**6); wMaster.setPoolCap(1000*10**6); vm.startPrank(LP); @@ -816,20 +815,20 @@ contract ProtocolTestnet is Test { //======= Revert on amount bigger than balance vm.startPrank(LP); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InsufficientBalance.selector)); wMaster.startWithdrawal(lpTokenUserBalance + 10); vm.stopPrank(); //======= Request Withdraw without any accrued fee vm.startPrank(LP); vm.expectEmit(); - emit ParentPool_WithdrawRequest(LP, ccipBnM, block.timestamp + 597_600); + emit ConceroParentPool_WithdrawRequest(LP, ccipBnM, block.timestamp + 597_600); wMaster.startWithdrawal(lpTokenUserBalance); vm.stopPrank(); //======= Revert on amount bigger than balance // vm.startPrank(LP); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_ActiveRequestNotFulfilledYet.selector)); + // vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_ActiveRequestNotFulfilledYet.selector)); // wMaster.startWithdrawal(lpTokenUserBalance); // vm.stopPrank(); @@ -839,7 +838,7 @@ contract ProtocolTestnet is Test { // //======= Revert Because money not arrived yet // vm.startPrank(LP); // lp.approve(address(wMaster), lpTokenUserBalance); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountNotAvailableYet.selector, 50*10**6)); + // vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_AmountNotAvailableYet.selector, 50*10**6)); // wMaster.completeWithdrawal(); // vm.stopPrank(); @@ -857,7 +856,7 @@ contract ProtocolTestnet is Test { // vm.startPrank(LP); // lp.approve(address(wMaster), lpTokenUserBalance); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); + // vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InsufficientBalance.selector)); // wMaster.completeWithdrawal(); // vm.stopPrank(); @@ -866,7 +865,7 @@ contract ProtocolTestnet is Test { // vm.startPrank(LP); // lp.approve(address(wMaster), lpTokenUserBalance); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_CallerIsNotTheProxy.selector, address(pool))); + // vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_CallerIsNotTheProxy.selector, address(pool))); // pool.completeWithdrawal(); // vm.stopPrank(); @@ -1044,7 +1043,7 @@ contract ProtocolTestnet is Test { //======= Increase the CAP vm.expectEmit(); vm.prank(Tester); - emit ParentPool_MasterPoolCapUpdated(1000*10**6); + emit ConceroParentPool_MasterPoolCapUpdated(1000*10**6); wMaster.setPoolCap(1000*10**6); vm.startPrank(LP); diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol index f7a099665..d2e7f9cca 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol @@ -71,7 +71,6 @@ contract ConceroChildPoolTest is Test { //======= Deploy MasterPool childPool = childDeploy.run( Orchestrator, - address(0), address(childProxy), mockLinkTokenAddress, mockSourceRouter, diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol index 9125b7bb3..ca08af8b9 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/Infra.t.sol @@ -6,7 +6,7 @@ import {Test, console} from "forge-std/Test.sol"; //Master & Infra Contracts import {DexSwap} from "contracts/DexSwap.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; import {ConceroBridge} from "contracts/ConceroBridge.sol"; import {Orchestrator} from "contracts/Orchestrator.sol"; import {LPToken} from "contracts/LPToken.sol"; @@ -70,7 +70,7 @@ interface IWETH is IERC20 { contract Infra is Test { //==== Instantiate Base Contracts DexSwap public dex; - ParentPool public pool; + ConceroParentPool public pool; ConceroBridge public concero; Orchestrator public orch; Orchestrator public orchEmpty; @@ -114,7 +114,7 @@ contract Infra is Test { //==== Wrapped contract Orchestrator wInfraSrc; Orchestrator wInfraDst; - ParentPool wMaster; + ConceroParentPool wMaster; ConceroChildPool wChild; @@ -272,7 +272,7 @@ contract Infra is Test { //====== Wrap the proxy as the implementation wInfraSrc = Orchestrator(address(proxy)); - wMaster = ParentPool(payable(address(masterProxy))); + wMaster = ConceroParentPool(payable(address(masterProxy))); //====== Update the MINTER on the LP Token vm.prank(Tester); diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol index 61977a7ed..32651e7c2 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol @@ -8,7 +8,7 @@ import {ParentPoolDeploy} from "../../../script/ParentPoolDeploy.s.sol"; import {LPTokenDeploy} from "../../../script/LPTokenDeploy.s.sol"; import {ParentPoolProxyDeploy} from "../../../script/ParentPoolProxyDeploy.s.sol"; -import {ParentPool} from "contracts/ParentPool.sol"; +import {ConceroParentPool} from "contracts/ConceroParentPool.sol"; import {LPToken} from "contracts/LPToken.sol"; import {ParentPoolProxy} from "contracts/Proxy/ParentPoolProxy.sol"; @@ -18,7 +18,7 @@ import {USDC} from "../../Mocks/USDC.sol"; contract ParentPoolTest is Test { //==== Instantiate Contracts - ParentPool public masterPool; + ConceroParentPool public masterPool; LPToken public lp; //==== Instantiate Proxies @@ -31,7 +31,7 @@ contract ParentPoolTest is Test { ParentPoolProxyDeploy masterProxyDeploy; //==== Wrapped contract - ParentPool wMaster; + ConceroParentPool wMaster; //======= Instantiate Mock USDC public usdc; @@ -102,91 +102,91 @@ contract ParentPoolTest is Test { vm.prank(Tester); lp.grantRole(keccak256("MINTER_ROLE"), address(masterPool)); - wMaster = ParentPool(payable(address(masterProxy))); + wMaster = ConceroParentPool(payable(address(masterProxy))); } /////////////////////////////////////////////////////////////// ////////////////////////Admin Functions//////////////////////// /////////////////////////////////////////////////////////////// ///setConceroContractSender/// - event ParentPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256); + event ConceroParentPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256); function test_setConceroContractSender() public { vm.prank(Tester); vm.expectEmit(); - emit ParentPool_ConceroSendersUpdated(mockDestinationChainSelector, address(mockChildPoolAddress), 1); + emit ConceroParentPool_ConceroSendersUpdated(mockDestinationChainSelector, address(mockChildPoolAddress), 1); wMaster.setConceroContractSender(mockDestinationChainSelector, address(mockChildPoolAddress), 1); assertEq(wMaster.s_contractsToReceiveFrom(mockDestinationChainSelector, address(mockChildPoolAddress)), 1); } - error ParentPool_NotContractOwner(); - error ParentPool_InvalidAddress(); + error ConceroParentPool_NotContractOwner(); + error ConceroParentPool_InvalidAddress(); function test_revertSetParentPool() public { - vm.expectRevert(abi.encodeWithSelector(ParentPool_NotContractOwner.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_NotContractOwner.selector)); wMaster.setConceroContractSender(mockDestinationChainSelector, address(mockChildPoolAddress), 1); vm.prank(Tester); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InvalidAddress.selector)); wMaster.setConceroContractSender(mockDestinationChainSelector, address(0), 1); } //setPools/// - event ParentPool_PoolReceiverUpdated(uint64 chainSelector, address contractAddress); + event ConceroParentPool_PoolReceiverUpdated(uint64 chainSelector, address contractAddress); function test_setPools() public { vm.prank(Tester); vm.expectEmit(); - emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); + emit ConceroParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); assertEq(wMaster.s_poolToSendTo(mockDestinationChainSelector), address(mockChildPoolAddress)); } - event ParentPool_RedistributionStarted(bytes32); + event ConceroParentPool_RedistributionStarted(bytes32); function test_revertSetPools() public { - vm.expectRevert(abi.encodeWithSelector(ParentPool_NotContractOwner.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_NotContractOwner.selector)); wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectEmit(); - emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); - emit ParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled. + emit ConceroParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); + emit ConceroParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled. wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), true); vm.prank(Tester); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InvalidAddress.selector)); wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InvalidAddress.selector)); wMaster.setPools(mockDestinationChainSelector, address(0), false); } function test_distributeLiquidity() public { uint64 fakeChainSelector = 15165481213213213; vm.prank(Messenger); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InvalidAddress.selector)); wMaster.distributeLiquidity(fakeChainSelector, 10*10**6); } ///orchestratorLoan/// - error ParentPool_ItsNotOrchestrator(address); - error ParentPool_InsufficientBalance(); - event ParentPool_SuccessfulDeposited(address, uint256, address); - error ParentPool_CallerIsNotTheProxy(address); + error ConceroParentPool_ItsNotOrchestrator(address); + error ConceroParentPool_InsufficientBalance(); + event ConceroParentPool_SuccessfulDeposited(address, uint256, address); + error ConceroParentPool_CallerIsNotTheProxy(address); function test_orchestratorLoanRevert() external { - vm.expectRevert(abi.encodeWithSelector(ParentPool_ItsNotOrchestrator.selector, address(this))); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_ItsNotOrchestrator.selector, address(this))); wMaster.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(0)); vm.startPrank(Orchestrator); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InvalidAddress.selector)); wMaster.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(0)); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InsufficientBalance.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InsufficientBalance.selector)); wMaster.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(this)); vm.startPrank(Orchestrator); - vm.expectRevert(abi.encodeWithSelector(ParentPool_CallerIsNotTheProxy.selector, address(masterPool))); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_CallerIsNotTheProxy.selector, address(masterPool))); masterPool.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(this)); vm.stopPrank(); @@ -210,46 +210,46 @@ contract ParentPoolTest is Test { wMaster.depositLiquidity(allowedAmountToDeposit); } - error ParentPool_AmountBelowMinimum(uint256 amount); - error ParentPool_ThereIsNoPoolToDistribute(); - error ParentPool_MaxCapReached(uint256); - event ParentPool_MasterPoolCapUpdated(uint256); + error ConceroParentPool_AmountBelowMinimum(uint256 amount); + error ConceroParentPool_ThereIsNoPoolToDistribute(); + error ConceroParentPool_MaxCapReached(uint256); + event ConceroParentPool_MasterPoolCapUpdated(uint256); function test_depositLiquidityRevert() public { uint256 allowedAmountToDeposit = 150*10**6; vm.prank(Tester); - vm.expectRevert(abi.encodeWithSelector(ParentPool_ThereIsNoPoolToDistribute.selector)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_ThereIsNoPoolToDistribute.selector)); wMaster.depositLiquidity(allowedAmountToDeposit); vm.prank(Tester); wMaster.setPools(mockDestinationChainSelector, mockChildPoolAddress, false); // vm.prank(Tester); - // vm.expectRevert(abi.encodeWithSelector(ParentPool_AmountBelowMinimum.selector, 100*10**6)); + // vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_AmountBelowMinimum.selector, 100*10**6)); // wMaster.depositLiquidity(amountToDeposit); vm.prank(Tester); wMaster.setPoolCap(120 *10**6); vm.prank(Tester); - vm.expectRevert(abi.encodeWithSelector(ParentPool_MaxCapReached.selector, 120 *10**6)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_MaxCapReached.selector, 120 *10**6)); wMaster.depositLiquidity(allowedAmountToDeposit); vm.prank(Tester); vm.expectEmit(); - emit ParentPool_MasterPoolCapUpdated(allowedAmountToDeposit); + emit ConceroParentPool_MasterPoolCapUpdated(allowedAmountToDeposit); wMaster.setPoolCap(allowedAmountToDeposit); } - event ParentPool_ChainAndAddressRemoved(uint64 chainSelector); + event ConceroParentPool_ChainAndAddressRemoved(uint64 chainSelector); function test_removePoolFromArray() public { vm.prank(Tester); wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectEmit(); - emit ParentPool_ChainAndAddressRemoved(mockDestinationChainSelector); - emit ParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled + emit ConceroParentPool_ChainAndAddressRemoved(mockDestinationChainSelector); + emit ConceroParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled wMaster.removePools(mockDestinationChainSelector); } } diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index 7d4fe3f69..e5e0736aa 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -7,7 +7,7 @@ import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol"; import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol"; import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/shared/interfaces/LinkTokenInterface.sol"; -import {ChildStorage} from "contracts/Libraries/ChildStorage.sol"; +import {ChildPoolStorage} from "contracts/Libraries/ChildPoolStorage.sol"; import {IStorage} from "./Interfaces/IStorage.sol"; import {IOrchestrator} from "./Interfaces/IOrchestrator.sol"; import {IPool} from "contracts/Interfaces/IPool.sol"; @@ -34,7 +34,7 @@ error ConceroChildPool_SenderNotAllowed(address sender); ///@notice error emitted if the array is empty. error ConceroChildPool_ThereIsNoPoolToDistribute(); -contract ConceroChildPool is CCIPReceiver, ChildStorage { +contract ConceroChildPool is CCIPReceiver, ChildPoolStorage { using SafeERC20 for IERC20; /////////////////////////////////////////////////////////// @@ -57,8 +57,6 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { LinkTokenInterface private immutable i_linkToken; ///@notice immutable variable to store the USDC address. IERC20 private immutable i_USDC; - ///@notice immutable variable to store the MasterPool Proxy address - address private immutable i_parentPoolProxyAddress; ///@notice Contract Owner address immutable i_owner; @@ -119,7 +117,6 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { constructor( address _orchestratorProxy, - address _masterPoolProxyAddress, address _childProxy, address _link, address _ccipRouter, @@ -130,7 +127,6 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { i_childProxy = _childProxy; i_linkToken = LinkTokenInterface(_link); i_USDC = IERC20(_usdc); - i_parentPoolProxyAddress = _masterPoolProxyAddress; i_owner = _owner; } @@ -335,7 +331,7 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { * @notice Function to check if a caller address is an allowed messenger * @param _messenger the address of the caller */ - function isMessenger(address _messenger) internal pure returns (bool isMessenger) { + function isMessenger(address _messenger) internal pure returns (bool _isMessenger) { address[] memory messengers = new address[](4); //Number of messengers. To define. messengers[0] = 0x11111003F38DfB073C6FeE2F5B35A0e57dAc4715; messengers[1] = 0x05CF0be5cAE993b4d7B70D691e063f1E0abeD267; diff --git a/packages/hardhat/contracts/ParentPool.sol b/packages/hardhat/contracts/ConceroParentPool.sol similarity index 87% rename from packages/hardhat/contracts/ParentPool.sol rename to packages/hardhat/contracts/ConceroParentPool.sol index f37c84aa2..b2df12e1f 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ConceroParentPool.sol @@ -13,7 +13,7 @@ import {ConceroAutomation} from "./ConceroAutomation.sol"; import {LPToken} from "./LPToken.sol"; import {IPool} from "contracts/Interfaces/IPool.sol"; import {IStorage} from "./Interfaces/IStorage.sol"; -import {ParentStorage} from "contracts/Libraries/ParentStorage.sol"; +import {ParentPoolStorage} from "contracts/Libraries/ParentPoolStorage.sol"; import {IOrchestrator} from "./Interfaces/IOrchestrator.sol"; import {Orchestrator} from "./Orchestrator.sol"; @@ -21,34 +21,34 @@ import {Orchestrator} from "./Orchestrator.sol"; //////////////////////// ERRORS //////////////////////// //////////////////////////////////////////////////////// ///@notice error emitted when the balance is not sufficient -error ParentPool_InsufficientBalance(); +error ConceroParentPool_InsufficientBalance(); ///@notice error emitted when the receiver is the address(0) -error ParentPool_InvalidAddress(); +error ConceroParentPool_InvalidAddress(); ///@notice error emitted when the caller is not a valid Messenger -error ParentPool_NotMessenger(address caller); +error ConceroParentPool_NotMessenger(address caller); ///@notice error emitted when the CCIP message sender is not allowed. -error ParentPool_SenderNotAllowed(address _sender); +error ConceroParentPool_SenderNotAllowed(address _sender); ///@notice error emitted when an attempt to create a new request is made while other is still active. -error ParentPool_ActiveRequestNotFulfilledYet(); +error ConceroParentPool_ActiveRequestNotFulfilledYet(); ///@notice error emitted when the contract doesn't have enough link balance -error ParentPool_NotEnoughLinkBalance(uint256 linkBalance, uint256 fees); +error ConceroParentPool_NotEnoughLinkBalance(uint256 linkBalance, uint256 fees); ///@notice error emitted when a LP try to deposit liquidity on the contract without pools -error ParentPool_ThereIsNoPoolToDistribute(); +error ConceroParentPool_ThereIsNoPoolToDistribute(); ///@notice emitted in depositLiquidity when the input amount is not enough -error ParentPool_AmountBelowMinimum(uint256 minAmount); +error ConceroParentPool_AmountBelowMinimum(uint256 minAmount); ///@notice emitted in withdrawLiquidity when the amount to withdraws is bigger than the balance -error ParentPool_AmountNotAvailableYet(uint256 received); +error ConceroParentPool_AmountNotAvailableYet(uint256 received); ///@notice error emitted when the caller is not the Orchestrator -error ParentPool_ItsNotOrchestrator(address caller); +error ConceroParentPool_ItsNotOrchestrator(address caller); ///@notice error emitted when the max amount accepted by the pool is reached -error ParentPool_MaxCapReached(uint256 maxCap); +error ConceroParentPool_MaxCapReached(uint256 maxCap); ///@notice error emitted when it's not the proxy calling the function -error ParentPool_CallerIsNotTheProxy(address caller); +error ConceroParentPool_CallerIsNotTheProxy(address caller); ///@notice error emitted when the caller is not the owner -error ParentPool_NotContractOwner(); +error ConceroParentPool_NotContractOwner(); //todo: ConceroParentPool -contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { +contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { /////////////////////// ///TYPE DECLARATIONS/// /////////////////////// @@ -86,7 +86,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { //////////////// ///IMMUTABLES/// //////////////// - ///@notice ParentPool proxy address + ///@notice ConceroParentPool proxy address address private immutable i_parentProxy; ///@notice Orchestrator Proxy immutable address address private immutable i_infraProxy; @@ -109,31 +109,31 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { //////////////////////// EVENTS //////////////////////// //////////////////////////////////////////////////////// ///@notice event emitted when a new withdraw request is made - event ParentPool_WithdrawRequest(address caller, IERC20 token, uint256 deadline); + event ConceroParentPool_WithdrawRequest(address caller, IERC20 token, uint256 deadline); ///@notice event emitted when a value is withdraw from the contract - event ParentPool_Withdrawn(address indexed to, address token, uint256 amount); + event ConceroParentPool_Withdrawn(address indexed to, address token, uint256 amount); ///@notice event emitted when a Cross-chain tx is received. - event ParentPool_CCIPReceived(bytes32 indexed ccipMessageId, uint64 srcChainSelector, address sender, address token, uint256 amount); + event ConceroParentPool_CCIPReceived(bytes32 indexed ccipMessageId, uint64 srcChainSelector, address sender, address token, uint256 amount); ///@notice event emitted when a Cross-chain message is sent. - event ParentPool_MessageSent(bytes32 messageId, uint64 destinationChainSelector, address receiver, address linkToken, uint256 fees); + event ConceroParentPool_MessageSent(bytes32 messageId, uint64 destinationChainSelector, address receiver, address linkToken, uint256 fees); ///@notice event emitted in depositLiquidity when a deposit is successful executed - event ParentPool_SuccessfulDeposited(address indexed liquidityProvider, uint256 _amount, IERC20 _token); + event ConceroParentPool_SuccessfulDeposited(address indexed liquidityProvider, uint256 _amount, IERC20 _token); ///@notice event emitted when a request is updated with the total USDC to withdraw - event ParentPool_RequestUpdated(address liquidityProvider); + event ConceroParentPool_RequestUpdated(address liquidityProvider); ///@notice event emitted when the Functions request return error event FunctionsRequestError(bytes32 requestId, IPool.RequestType requestType); ///@notice event emitted when a Concero pool is added - event ParentPool_PoolReceiverUpdated(uint64 chainSelector, address pool); + event ConceroParentPool_PoolReceiverUpdated(uint64 chainSelector, address pool); ///@notice event emitted when a allowed Cross-chain contract is updated - event ParentPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256 isAllowed); + event ConceroParentPool_ConceroSendersUpdated(uint64 chainSelector, address conceroContract, uint256 isAllowed); ///@notice event emitted in setConceroContract when the address is emitted - event ParentPool_ConceroContractUpdated(address concero); + event ConceroParentPool_ConceroContractUpdated(address concero); ///@notice event emitted when a contract is removed from the distribution array - event ParentPool_ChainAndAddressRemoved(uint64 _chainSelector); + event ConceroParentPool_ChainAndAddressRemoved(uint64 _chainSelector); ///@notice event emitted when a pool is removed and the redistribution process start - event ParentPool_RedistributionStarted(bytes32 requestId); + event ConceroParentPool_RedistributionStarted(bytes32 requestId); ///@notice event emitted when the MasterPool Cap is increased - event ParentPool_MasterPoolCapUpdated(uint256 _newCap); + event ConceroParentPool_MasterPoolCapUpdated(uint256 _newCap); /////////////// ///MODIFIERS/// @@ -144,7 +144,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @param _sender address of the sender contract */ modifier onlyAllowlistedSenderAndChainSelector(uint64 _chainSelector, address _sender) { - if (s_contractsToReceiveFrom[_chainSelector][_sender] != ALLOWED) revert ParentPool_SenderNotAllowed(_sender); + if (s_contractsToReceiveFrom[_chainSelector][_sender] != ALLOWED) revert ConceroParentPool_SenderNotAllowed(_sender); _; } @@ -152,12 +152,12 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice modifier to ensure if the function is being executed in the proxy context. */ modifier isProxy() { - if (address(this) != i_parentProxy) revert ParentPool_CallerIsNotTheProxy(address(this)); + if (address(this) != i_parentProxy) revert ConceroParentPool_CallerIsNotTheProxy(address(this)); _; } modifier onlyOwner() { - if (msg.sender != i_owner) revert ParentPool_NotContractOwner(); + if (msg.sender != i_owner) revert ConceroParentPool_NotContractOwner(); _; } @@ -165,7 +165,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @notice modifier to check if the caller is the an approved messenger */ modifier onlyMessenger() { - if (isMessenger(msg.sender) == false) revert ParentPool_NotMessenger(msg.sender); + if (isMessenger(msg.sender) == false) revert ConceroParentPool_NotMessenger(msg.sender); _; } @@ -210,9 +210,9 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev for ether transfer, the _receiver need to be known and trusted */ function orchestratorLoan(address _token, uint256 _amount, address _receiver) external payable isProxy { - if (msg.sender != i_infraProxy) revert ParentPool_ItsNotOrchestrator(msg.sender); - if (_receiver == address(0)) revert ParentPool_InvalidAddress(); - if (_amount > (IERC20(_token).balanceOf(address(this)) - s_withdrawRequests)) revert ParentPool_InsufficientBalance(); + if (msg.sender != i_infraProxy) revert ConceroParentPool_ItsNotOrchestrator(msg.sender); + if (_receiver == address(0)) revert ConceroParentPool_InvalidAddress(); + if (_amount > (IERC20(_token).balanceOf(address(this)) - s_withdrawRequests)) revert ConceroParentPool_InsufficientBalance(); s_loansInUse = s_loansInUse + _amount; @@ -224,12 +224,12 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @param _usdcAmount the amount to be deposited */ function depositLiquidity(uint256 _usdcAmount) external isProxy { - if (_usdcAmount < MIN_DEPOSIT) revert ParentPool_AmountBelowMinimum(MIN_DEPOSIT); - if (s_maxDeposit != 0 && s_maxDeposit < _usdcAmount + i_USDC.balanceOf(address(this)) + s_loansInUse) revert ParentPool_MaxCapReached(s_maxDeposit); + if (_usdcAmount < MIN_DEPOSIT) revert ConceroParentPool_AmountBelowMinimum(MIN_DEPOSIT); + if (s_maxDeposit != 0 && s_maxDeposit < _usdcAmount + i_USDC.balanceOf(address(this)) + s_loansInUse) revert ConceroParentPool_MaxCapReached(s_maxDeposit); uint256 numberOfPools = s_poolsToDistribute.length; - if (numberOfPools < ALLOWED) revert ParentPool_ThereIsNoPoolToDistribute(); + if (numberOfPools < ALLOWED) revert ConceroParentPool_ThereIsNoPoolToDistribute(); // uint256 depositFee = _calculateDepositTransactionFee(_usdcAmount); // uint256 depositMinusFee = _usdcAmount - _convertToUSDCTokenDecimals(depositFee); @@ -249,7 +249,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { amount: _usdcAmount }); - emit ParentPool_SuccessfulDeposited(msg.sender, _usdcAmount, i_USDC); + emit ConceroParentPool_SuccessfulDeposited(msg.sender, _usdcAmount, i_USDC); i_USDC.safeTransferFrom(msg.sender, address(this), _usdcAmount); // i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(depositFee)); @@ -262,8 +262,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @param _lpAmount the amount of lp token the user wants to burn to get USDC back. */ function startWithdrawal(uint256 _lpAmount) external isProxy { - if (i_lp.balanceOf(msg.sender) < _lpAmount) revert ParentPool_InsufficientBalance(); - if (s_pendingWithdrawRequests[msg.sender].amountToBurn > 0) revert ParentPool_ActiveRequestNotFulfilledYet(); + if (i_lp.balanceOf(msg.sender) < _lpAmount) revert ConceroParentPool_InsufficientBalance(); + if (s_pendingWithdrawRequests[msg.sender].amountToBurn > 0) revert ConceroParentPool_ActiveRequestNotFulfilledYet(); bytes[] memory args = new bytes[](2); args[0] = abi.encodePacked(s_hashSum); @@ -279,7 +279,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { amount: _lpAmount }); - emit ParentPool_WithdrawRequest(msg.sender, i_USDC, block.timestamp + WITHDRAW_DEADLINE); + emit ConceroParentPool_WithdrawRequest(msg.sender, i_USDC, block.timestamp + WITHDRAW_DEADLINE); } /** @@ -291,8 +291,8 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { function completeWithdrawal() external isProxy { IPool.WithdrawRequests memory withdraw = s_pendingWithdrawRequests[msg.sender]; - if (withdraw.amountToReceive > 0) revert ParentPool_AmountNotAvailableYet(withdraw.amountToReceive); - if (withdraw.amountEarned > i_USDC.balanceOf(address(this))) revert ParentPool_InsufficientBalance(); + if (withdraw.amountToReceive > 0) revert ConceroParentPool_AmountNotAvailableYet(withdraw.amountToReceive); + if (withdraw.amountEarned > i_USDC.balanceOf(address(this))) revert ConceroParentPool_InsufficientBalance(); s_withdrawRequests = s_withdrawRequests > withdraw.amountEarned ? s_withdrawRequests - withdraw.amountEarned : 0; @@ -301,7 +301,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // uint256 withdrawFees = _calculateWithdrawTransactionsFee(withdraw.amountEarned); // uint256 withdrawAmountMinusFees = withdraw.amountEarned - _convertToUSDCTokenDecimals(withdrawFees); - emit ParentPool_Withdrawn(msg.sender, address(i_USDC), withdraw.amountEarned); + emit ConceroParentPool_Withdrawn(msg.sender, address(i_USDC), withdraw.amountEarned); IERC20(i_lp).safeTransferFrom(msg.sender, address(this), withdraw.amountToBurn); i_lp.burn(withdraw.amountToBurn); @@ -316,7 +316,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @param _amountToSend the amount to redistribute between pools. */ function distributeLiquidity(uint64 _chainSelector, uint256 _amountToSend) external isProxy onlyMessenger { - if (s_poolToSendTo[_chainSelector] == address(0)) revert ParentPool_InvalidAddress(); + if (s_poolToSendTo[_chainSelector] == address(0)) revert ConceroParentPool_InvalidAddress(); _ccipSend(_chainSelector, _amountToSend); } @@ -333,10 +333,10 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev this functions is used on ConceroPool.sol */ function setConceroContractSender(uint64 _chainSelector, address _contractAddress, uint256 _isAllowed) external payable isProxy onlyOwner { - if (_contractAddress == address(0)) revert ParentPool_InvalidAddress(); + if (_contractAddress == address(0)) revert ConceroParentPool_InvalidAddress(); s_contractsToReceiveFrom[_chainSelector][_contractAddress] = _isAllowed; - emit ParentPool_ConceroSendersUpdated(_chainSelector, _contractAddress, _isAllowed); + emit ConceroParentPool_ConceroSendersUpdated(_chainSelector, _contractAddress, _isAllowed); } /** @@ -346,7 +346,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { function setPoolCap(uint256 _newCap) external payable isProxy onlyOwner { s_maxDeposit = _newCap; - emit ParentPool_MasterPoolCapUpdated(_newCap); + emit ConceroParentPool_MasterPoolCapUpdated(_newCap); } function setDonHostedSecretsSlotId(uint8 _slotId) external payable isProxy onlyOwner { @@ -374,12 +374,12 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @dev this functions is used on ConceroPool.sol */ function setPools(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { - if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); + if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroParentPool_InvalidAddress(); s_poolsToDistribute.push(_chainSelector); s_poolToSendTo[_chainSelector] = _pool; - emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); + emit ConceroParentPool_PoolReceiverUpdated(_chainSelector, _pool); if (isRebalance == true) { //balancePool = Query balance from ChildPools & ParentPool @@ -400,7 +400,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // s_requests[requestId] = CLFRebalance({ // }); - emit ParentPool_RedistributionStarted(requestId); + emit ConceroParentPool_RedistributionStarted(requestId); } } @@ -422,7 +422,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { } } - emit ParentPool_ChainAndAddressRemoved(_chainSelector); + emit ConceroParentPool_ChainAndAddressRemoved(_chainSelector); //send through functions? // 1. Trigger the liquidatePool functions to transfer money equally to other pools @@ -439,7 +439,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { // s_requests[requestId] = CLFRebalance({ // }); - emit ParentPool_RedistributionStarted(requestId); + emit ConceroParentPool_RedistributionStarted(requestId); } //////////////// @@ -481,7 +481,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { s_withdrawRequests = s_withdrawRequests + any2EvmMessage.destTokenAmounts[0].amount; } - emit ParentPool_CCIPReceived( + emit ConceroParentPool_CCIPReceived( any2EvmMessage.messageId, any2EvmMessage.sourceChainSelector, abi.decode(any2EvmMessage.sender, (address)), @@ -514,14 +514,14 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); - if (fees > i_linkToken.balanceOf(address(this))) revert ParentPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); + if (fees > i_linkToken.balanceOf(address(this))) revert ConceroParentPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); i_USDC.approve(i_ccipRouter, _amountToDistribute); i_linkToken.approve(i_ccipRouter, fees); messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); - emit ParentPool_MessageSent(messageId, _chainSelector, s_poolToSendTo[_chainSelector], address(i_linkToken), fees); + emit ConceroParentPool_MessageSent(messageId, _chainSelector, s_poolToSendTo[_chainSelector], address(i_linkToken), fees); } function _buildCCIPMessage(uint64 _chainSelector, address _token, uint256 _amount) internal view returns (Client.EVM2AnyMessage memory) { @@ -643,7 +643,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { s_pendingWithdrawRequests[_liquidityProvider] = request; i_automation.addPendingWithdrawal(_liquidityProvider); - emit ParentPool_RequestUpdated(_liquidityProvider); + emit ConceroParentPool_RequestUpdated(_liquidityProvider); } // function _calculateDepositTransactionFee(uint256 _amountToDistribute) internal view returns(uint256 _totalUSDCCost){ diff --git a/packages/hardhat/contracts/Libraries/ChildStorage.sol b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol similarity index 94% rename from packages/hardhat/contracts/Libraries/ChildStorage.sol rename to packages/hardhat/contracts/Libraries/ChildPoolStorage.sol index f352a65f6..89fd6b1b6 100644 --- a/packages/hardhat/contracts/Libraries/ChildStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol @@ -1,8 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.20; -// todo: ChildPoolStorage -contract ChildStorage { +contract ChildPoolStorage { ///////////////////// ///STATE VARIABLES/// ///////////////////// diff --git a/packages/hardhat/contracts/Libraries/ParentStorage.sol b/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol similarity index 98% rename from packages/hardhat/contracts/Libraries/ParentStorage.sol rename to packages/hardhat/contracts/Libraries/ParentPoolStorage.sol index a1d713423..aff58716c 100644 --- a/packages/hardhat/contracts/Libraries/ParentStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.20; import {IPool} from "contracts/Interfaces/IPool.sol"; // todo: ParentPoolStorage -contract ParentStorage { +contract ParentPoolStorage { ///////////////////// ///STATE VARIABLES/// ///////////////////// diff --git a/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol b/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol index 36045f375..dc447855c 100644 --- a/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol +++ b/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol @@ -7,7 +7,7 @@ import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.s import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol"; -import {ChildStorage} from "../Libraries/ChildStorage.sol"; +import {ChildPoolStorage} from "../Libraries/ChildPoolStorage.sol"; /** * @dev Interface for {TransparentUpgradeableProxy}. In order to implement transparency, {TransparentUpgradeableProxy} @@ -60,7 +60,7 @@ error Proxy_ContractPaused(); * function and the functions declared in {ITransparentUpgradeableProxy} will be resolved in favor of the new one. This * could render the `upgradeToAndCall` function inaccessible, preventing upgradeability and compromising transparency. */ -contract ChildPoolProxy is ChildStorage, ERC1967Proxy { +contract ChildPoolProxy is ChildPoolStorage, ERC1967Proxy { // An immutable address for the admin to avoid unnecessary SLOADs before each call // at the expense of removing the ability to change the admin once it's set. // This is acceptable if the admin is always a ProxyAdmin instance or similar contract diff --git a/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol b/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol index c95e96e24..39a22ba48 100644 --- a/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol +++ b/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol @@ -7,7 +7,7 @@ import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.s import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol"; -import {ParentStorage} from "../Libraries/ParentStorage.sol"; +import {ParentPoolStorage} from "../Libraries/ParentPoolStorage.sol"; /** * @dev Interface for {TransparentUpgradeableProxy}. In order to implement transparency, {TransparentUpgradeableProxy} @@ -60,7 +60,7 @@ error Proxy_ContractPaused(); * function and the functions declared in {ITransparentUpgradeableProxy} will be resolved in favor of the new one. This * could render the `upgradeToAndCall` function inaccessible, preventing upgradeability and compromising transparency. */ -contract ParentPoolProxy is ERC1967Proxy, ParentStorage { +contract ParentPoolProxy is ERC1967Proxy, ParentPoolStorage { // An immutable address for the admin to avoid unnecessary SLOADs before each call // at the expense of removing the ability to change the admin once it's set. // This is acceptable if the admin is always a ProxyAdmin instance or similar contract diff --git a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts index 4327171db..0ec501022 100644 --- a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts +++ b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts @@ -300,13 +300,13 @@ async function removePools(chain: CNetwork, abi, chainSelectors: string[]) { }); log( `Remove ${chainName}:${chainSelector} from list of senders. Gas used: ${deletePoolGasUsed.toString()}`, - "removePoolFromListOfSenders", + "removePools", ); } } export async function setParentPoolVariables(chain: CNetwork, isSetSecretsNeeded: boolean, slotId: number) { - const { abi: ParentPoolAbi } = await load("../artifacts/contracts/ParentPool.sol/ParentPool.json"); + const { abi: ParentPoolAbi } = await load("../artifacts/contracts/ConceroParentPool.sol/ConceroParentPool.json"); await setParentPoolJsHashes(chain, ParentPoolAbi); await setParentPoolCap(chain, ParentPoolAbi); diff --git a/packages/hardhat/test/CompleteWithdrawal.ts b/packages/hardhat/test/CompleteWithdrawal.ts index 1bb5bfefe..4aaf5383e 100644 --- a/packages/hardhat/test/CompleteWithdrawal.ts +++ b/packages/hardhat/test/CompleteWithdrawal.ts @@ -9,7 +9,7 @@ import { privateKeyToAccount } from "viem/accounts"; import { Address, createPublicClient, createWalletClient, PrivateKeyAccount } from "viem"; import { PublicClient } from "viem/clients/createPublicClient"; import { approve } from "./utils/approve"; -import { abi as ParentPoolAbi } from "../artifacts/contracts/ParentPool.sol/ParentPool.json"; +import { abi as ParentPoolAbi } from "../artifacts/contracts/ConceroParentPool.sol/ConceroParentPool.json"; import { chainsMap } from "./utils/chainsMap"; const srcChainSelector = process.env.CL_CCIP_CHAIN_SELECTOR_BASE_SEPOLIA; diff --git a/packages/hardhat/test/DepositUsdcToPool.ts b/packages/hardhat/test/DepositUsdcToPool.ts index 1f6fd1a90..84739bccf 100644 --- a/packages/hardhat/test/DepositUsdcToPool.ts +++ b/packages/hardhat/test/DepositUsdcToPool.ts @@ -8,7 +8,7 @@ import { privateKeyToAccount } from "viem/accounts"; import { Address, createPublicClient, createWalletClient, PrivateKeyAccount } from "viem"; import { PublicClient } from "viem/clients/createPublicClient"; import { approve } from "./utils/approve"; -import { abi as ParentPoolAbi } from "../artifacts/contracts/ParentPool.sol/ParentPool.json"; +import { abi as ParentPoolAbi } from "../artifacts/contracts/ConceroParentPool.sol/ConceroParentPool.json"; import { chainsMap } from "./utils/chainsMap"; const srcChainSelector = process.env.CL_CCIP_CHAIN_SELECTOR_BASE; diff --git a/packages/hardhat/test/WithdrawPoolUsdc.ts b/packages/hardhat/test/WithdrawPoolUsdc.ts index 37a747bb7..c15083ded 100644 --- a/packages/hardhat/test/WithdrawPoolUsdc.ts +++ b/packages/hardhat/test/WithdrawPoolUsdc.ts @@ -9,7 +9,7 @@ import { privateKeyToAccount } from "viem/accounts"; import { Address, createPublicClient, createWalletClient, PrivateKeyAccount } from "viem"; import { PublicClient } from "viem/clients/createPublicClient"; import { approve } from "./utils/approve"; -import { abi as ParentPoolAbi } from "../artifacts/contracts/ParentPool.sol/ParentPool.json"; +import { abi as ParentPoolAbi } from "../artifacts/contracts/ConceroParentPool.sol/ConceroParentPool.json"; import { chainsMap } from "./utils/chainsMap"; const srcChainSelector = process.env.CL_CCIP_CHAIN_SELECTOR_BASE_SEPOLIA; From 3ea8f665d46ceaffaaeb1b237307ec864210735b Mon Sep 17 00:00:00 2001 From: Oleg Kirillovich Date: Sun, 14 Jul 2024 19:22:30 +0100 Subject: [PATCH 10/17] todos --- packages/hardhat/contracts/Libraries/ChildPoolStorage.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol index 89fd6b1b6..ba8e05104 100644 --- a/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol @@ -13,7 +13,7 @@ contract ChildPoolStorage { ///////////// ///STORAGE/// ///////////// - ///@notice array of Pools to receive Liquidity through `ccipSend` function + ///@notice array of chain IDS of Pools to receive Liquidity through `ccipSend` function uint64[] s_poolsToDistribute; ///@notice Mapping to keep track of allowed pool senders From f77ce930807f439af25aa12049e888727b0a0ad0 Mon Sep 17 00:00:00 2001 From: Barba Date: Sun, 14 Jul 2024 22:29:07 -0300 Subject: [PATCH 11/17] Update setChildProxyVariables script and improve test coverage --- packages/foundry/coverage.txt | 309 ----------- packages/foundry/coverageTwo.txt | 520 ++++++++++++++++++ .../MainnetFork/ProtocolMainnet.t.sol | 6 + .../TestnetFork/ProtocolTestnet.t.sol | 40 +- .../hardhat/contracts/ConceroChildPool.sol | 16 +- .../hardhat/contracts/ConceroParentPool.sol | 30 +- .../contracts/Libraries/ParentPoolStorage.sol | 2 +- .../deployPool/setChildProxyVariables.ts | 48 ++ 8 files changed, 636 insertions(+), 335 deletions(-) delete mode 100644 packages/foundry/coverage.txt create mode 100644 packages/foundry/coverageTwo.txt diff --git a/packages/foundry/coverage.txt b/packages/foundry/coverage.txt deleted file mode 100644 index ebd5be9e0..000000000 --- a/packages/foundry/coverage.txt +++ /dev/null @@ -1,309 +0,0 @@ -Uncovered for ../hardhat/contracts/ConceroAutomation.sol: - -Uncovered for ../hardhat/contracts/ConceroBridge.sol: - -Uncovered for ../hardhat/contracts/ConceroChildPool.sol: -- Branch (branch: 3, path: 1) (location: source ID 3, line 106, chars 4910-5025, hits: 0) -- Statement (location: source ID 3, line 106, chars 4976-5025, hits: 0) - -Uncovered for ../hardhat/contracts/DexSwap.sol: -- Branch (branch: 1, path: 1) (location: source ID 7, line 81, chars 3713-3913, hits: 0) -- Statement (location: source ID 7, line 82, chars 3824-3874, hits: 0) -- Branch (branch: 2, path: 1) (location: source ID 7, line 82, chars 3771-3904, hits: 0) -- Statement (location: source ID 7, line 82, chars 3876-3904, hits: 0) -- Line (location: source ID 7, line 88, chars 4108-4162, hits: 0) -- Statement (location: source ID 7, line 88, chars 4108-4162, hits: 0) -- Statement (location: source ID 7, line 88, chars 4108-4131, hits: 0) -- Statement (location: source ID 7, line 88, chars 4113-4131, hits: 0) -- Statement (location: source ID 7, line 88, chars 4149-4162, hits: 0) - - -- Statement (location: source ID 7, line 287, chars 13003-13033, hits: 0) -- Branch (branch: 33, path: 1) (location: source ID 7, line 287, chars 12965-13428, hits: 0) -- Line (location: source ID 7, line 299, chars 13442-13693, hits: 0) -- Statement (location: source ID 7, line 299, chars 13442-13693, hits: 0) -- Statement (location: source ID 7, line 299, chars 13487-13693, hits: 0) -- Line (location: source ID 7, line 307, chars 13702-13788, hits: 0) -- Statement (location: source ID 7, line 307, chars 13702-13788, hits: 0) -- Line (location: source ID 7, line 309, chars 13797-13842, hits: 0) -- Statement (location: source ID 7, line 309, chars 13797-13842, hits: 0) -- Line (location: source ID 7, line 371, chars 16943-16984, hits: 0) -- Statement (location: source ID 7, line 371, chars 16943-16984, hits: 0) -- Line (location: source ID 7, line 377, chars 17082-17128, hits: 0) -- Statement (location: source ID 7, line 377, chars 17082-17128, hits: 0) - -Uncovered for ../hardhat/contracts/Orchestrator.sol: -- Function "" (location: source ID 21, line 65, chars 2953-3284, hits: 0) -- Line (location: source ID 21, line 66, chars 3110-3146, hits: 0) -- Statement (location: source ID 21, line 66, chars 3110-3146, hits: 0) -- Line (location: source ID 21, line 67, chars 3152-3172, hits: 0) -- Statement (location: source ID 21, line 67, chars 3152-3172, hits: 0) -- Line (location: source ID 21, line 68, chars 3178-3198, hits: 0) -- Statement (location: source ID 21, line 68, chars 3178-3198, hits: 0) -- Line (location: source ID 21, line 69, chars 3204-3218, hits: 0) -- Statement (location: source ID 21, line 69, chars 3204-3218, hits: 0) -- Line (location: source ID 21, line 70, chars 3224-3240, hits: 0) -- Statement (location: source ID 21, line 70, chars 3224-3240, hits: 0) -- Line (location: source ID 21, line 71, chars 3246-3279, hits: 0) -- Statement (location: source ID 21, line 71, chars 3246-3279, hits: 0) -- Branch (branch: 0, path: 1) (location: source ID 21, line 78, chars 3411-3569, hits: 0) -- Branch (branch: 1, path: 1) (location: source ID 21, line 80, chars 3505-3562, hits: 0) -- Statement (location: source ID 21, line 80, chars 3527-3562, hits: 0) -- Statement (location: source ID 21, line 82, chars 3608-3643, hits: 0) -- Statement (location: source ID 21, line 88, chars 3834-3873, hits: 0) -- Statement (location: source ID 21, line 99, chars 4257-4296, hits: 0) -- Statement (location: source ID 21, line 99, chars 4286-4296, hits: 0) -- Statement (location: source ID 21, line 99, chars 4298-4340, hits: 0) -- Branch (branch: 6, path: 1) (location: source ID 21, line 106, chars 4483-4670, hits: 0) -- Branch (branch: 7, path: 1) (location: source ID 21, line 107, chars 4513-4664, hits: 0) -- Function "getSrcTotalFeeInUsdc" (location: source ID 21, line 122, chars 4837-5092, hits: 0) -- Line (location: source ID 21, line 123, chars 4967-5087, hits: 0) -- Statement (location: source ID 21, line 123, chars 4967-5087, hits: 0) -- Statement (location: source ID 21, line 123, chars 4974-5087, hits: 0) -- Function "getSrcTotalFeeInUsdcViaDelegateCall" (location: source ID 21, line 126, chars 5096-5560, hits: 0) -- Line (location: source ID 21, line 127, chars 5236-5407, hits: 0) -- Statement (location: source ID 21, line 127, chars 5236-5407, hits: 0) -- Statement (location: source ID 21, line 127, chars 5272-5407, hits: 0) -- Line (location: source ID 21, line 131, chars 5418-5434, hits: 0) -- Statement (location: source ID 21, line 131, chars 5418-5434, hits: 0) -- Branch (branch: 8, path: 0) (location: source ID 21, line 131, chars 5414-5490, hits: 0) -- Branch (branch: 8, path: 1) (location: source ID 21, line 131, chars 5414-5490, hits: 0) -- Statement (location: source ID 21, line 131, chars 5436-5490, hits: 0) -- Line (location: source ID 21, line 133, chars 5497-5555, hits: 0) -- Statement (location: source ID 21, line 133, chars 5497-5555, hits: 0) -- Statement (location: source ID 21, line 133, chars 5504-5555, hits: 0) -- Branch (branch: 9, path: 1) (location: source ID 21, line 141, chars 5836-5970, hits: 0) -- Statement (location: source ID 21, line 141, chars 5933-5970, hits: 0) -- Branch (branch: 11, path: 1) (location: source ID 21, line 154, chars 6501-6590, hits: 0) -- Statement (location: source ID 21, line 154, chars 6529-6590, hits: 0) -- Branch (branch: 14, path: 1) (location: source ID 21, line 182, chars 7748-7837, hits: 0) -- Statement (location: source ID 21, line 182, chars 7776-7837, hits: 0) -- Function "addUnconfirmedTX" (location: source ID 21, line 185, chars 7846-8412, hits: 0) -- Line (location: source ID 21, line 195, chars 8102-8325, hits: 0) -- Statement (location: source ID 21, line 195, chars 8102-8325, hits: 0) -- Statement (location: source ID 21, line 195, chars 8138-8325, hits: 0) -- Line (location: source ID 21, line 198, chars 8335-8351, hits: 0) -- Statement (location: source ID 21, line 198, chars 8335-8351, hits: 0) -- Branch (branch: 15, path: 0) (location: source ID 21, line 198, chars 8331-8407, hits: 0) -- Branch (branch: 15, path: 1) (location: source ID 21, line 198, chars 8331-8407, hits: 0) -- Statement (location: source ID 21, line 198, chars 8353-8407, hits: 0) -- Branch (branch: 17, path: 0) (location: source ID 21, line 210, chars 8811-8897, hits: 0) -- Line (location: source ID 21, line 212, chars 8904-8949, hits: 0) -- Statement (location: source ID 21, line 212, chars 8904-8949, hits: 0) -- Function "withdraw" (location: source ID 21, line 215, chars 8958-9340, hits: 0) -- Line (location: source ID 21, line 216, chars 9059-9120, hits: 0) -- Statement (location: source ID 21, line 216, chars 9059-9120, hits: 0) -- Statement (location: source ID 21, line 216, chars 9077-9120, hits: 0) -- Line (location: source ID 21, line 217, chars 9130-9146, hits: 0) -- Statement (location: source ID 21, line 217, chars 9130-9146, hits: 0) -- Branch (branch: 18, path: 0) (location: source ID 21, line 217, chars 9126-9183, hits: 0) -- Branch (branch: 18, path: 1) (location: source ID 21, line 217, chars 9126-9183, hits: 0) -- Statement (location: source ID 21, line 217, chars 9148-9183, hits: 0) -- Line (location: source ID 21, line 219, chars 9194-9213, hits: 0) -- Statement (location: source ID 21, line 219, chars 9194-9213, hits: 0) -- Statement (location: source ID 21, line 219, chars 9203-9213, hits: 0) -- Branch (branch: 19, path: 0) (location: source ID 21, line 219, chars 9190-9280, hits: 0) -- Branch (branch: 19, path: 1) (location: source ID 21, line 219, chars 9190-9280, hits: 0) -- Line (location: source ID 21, line 220, chars 9223-9273, hits: 0) -- Statement (location: source ID 21, line 220, chars 9223-9273, hits: 0) -- Line (location: source ID 21, line 222, chars 9294-9329, hits: 0) -- Statement (location: source ID 21, line 222, chars 9294-9329, hits: 0) -- Branch (branch: 24, path: 0) (location: source ID 21, line 256, chars 10718-10800, hits: 0) -- Line (location: source ID 21, line 257, chars 10771-10793, hits: 0) -- Statement (location: source ID 21, line 257, chars 10771-10793, hits: 0) -- Branch (branch: 25, path: 0) (location: source ID 21, line 258, chars 10806-10880, hits: 0) -- Line (location: source ID 21, line 259, chars 10855-10873, hits: 0) -- Statement (location: source ID 21, line 259, chars 10855-10873, hits: 0) -- Branch (branch: 26, path: 0) (location: source ID 21, line 260, chars 10886-10969, hits: 0) -- Line (location: source ID 21, line 261, chars 10940-10962, hits: 0) -- Statement (location: source ID 21, line 261, chars 10940-10962, hits: 0) -- Branch (branch: 27, path: 1) (location: source ID 21, line 262, chars 10975-11055, hits: 0) -- Line (location: source ID 21, line 263, chars 11027-11048, hits: 0) -- Statement (location: source ID 21, line 263, chars 11027-11048, hits: 0) - -Uncovered for ../hardhat/contracts/ParentPool.sol: -- Function "onlyAllowlistedSenderAndChainSelector" (location: source ID 22, line 141, chars 8416-8630, hits: 0) -- Line (location: source ID 22, line 142, chars 8513-8573, hits: 0) -- Statement (location: source ID 22, line 142, chars 8513-8573, hits: 0) -- Branch (branch: 0, path: 0) (location: source ID 22, line 142, chars 8509-8618, hits: 0) -- Branch (branch: 0, path: 1) (location: source ID 22, line 142, chars 8509-8618, hits: 0) -- Statement (location: source ID 22, line 142, chars 8575-8618, hits: 0) -- Branch (branch: 1, path: 0) (location: source ID 22, line 150, chars 8759-8847, hits: 0) -- Branch (branch: 1, path: 1) (location: source ID 22, line 150, chars 8759-8847, hits: 0) -- Branch (branch: 2, path: 0) (location: source ID 22, line 155, chars 8890-8953, hits: 0) -- Branch (branch: 2, path: 1) (location: source ID 22, line 155, chars 8890-8953, hits: 0) -- Function "" (location: source ID 22, line 164, chars 9242-9890, hits: 0) -- Line (location: source ID 22, line 177, chars 9585-9601, hits: 0) -- Statement (location: source ID 22, line 177, chars 9585-9601, hits: 0) -- Line (location: source ID 22, line 178, chars 9607-9641, hits: 0) -- Statement (location: source ID 22, line 178, chars 9607-9641, hits: 0) -- Line (location: source ID 22, line 179, chars 9647-9675, hits: 0) -- Statement (location: source ID 22, line 179, chars 9647-9675, hits: 0) -- Line (location: source ID 22, line 180, chars 9681-9720, hits: 0) -- Statement (location: source ID 22, line 180, chars 9681-9720, hits: 0) -- Line (location: source ID 22, line 181, chars 9726-9748, hits: 0) -- Statement (location: source ID 22, line 181, chars 9726-9748, hits: 0) -- Line (location: source ID 22, line 182, chars 9754-9778, hits: 0) -- Statement (location: source ID 22, line 182, chars 9754-9778, hits: 0) -- Line (location: source ID 22, line 183, chars 9784-9829, hits: 0) -- Statement (location: source ID 22, line 183, chars 9784-9829, hits: 0) -- Line (location: source ID 22, line 184, chars 9835-9863, hits: 0) -- Statement (location: source ID 22, line 184, chars 9835-9863, hits: 0) -- Line (location: source ID 22, line 185, chars 9869-9885, hits: 0) -- Statement (location: source ID 22, line 185, chars 9869-9885, hits: 0) -- Branch (branch: 5, path: 1) (location: source ID 22, line 202, chars 10629-10746, hits: 0) -- Line (location: source ID 22, line 204, chars 10753-10790, hits: 0) -- Statement (location: source ID 22, line 204, chars 10753-10790, hits: 0) -- Line (location: source ID 22, line 206, chars 10797-10844, hits: 0) -- Statement (location: source ID 22, line 206, chars 10797-10844, hits: 0) -- Branch (branch: 7, path: 1) (location: source ID 22, line 215, chars 11142-11289, hits: 0) -- Branch (branch: 9, path: 1) (location: source ID 22, line 252, chars 12739-12822, hits: 0) -- Statement (location: source ID 22, line 252, chars 12783-12822, hits: 0) -- Branch (branch: 10, path: 1) (location: source ID 22, line 253, chars 12828-12936, hits: 0) -- Statement (location: source ID 22, line 253, chars 12888-12936, hits: 0) -- Line (location: source ID 22, line 269, chars 13394-13482, hits: 0) -- Statement (location: source ID 22, line 269, chars 13394-13482, hits: 0) -- Function "completeWithdrawal" (location: source ID 22, line 278, chars 13771-14846, hits: 0) -- Line (location: source ID 22, line 279, chars 13824-13908, hits: 0) -- Statement (location: source ID 22, line 279, chars 13824-13908, hits: 0) -- Line (location: source ID 22, line 281, chars 13919-13947, hits: 0) -- Statement (location: source ID 22, line 281, chars 13919-13947, hits: 0) -- Branch (branch: 11, path: 0) (location: source ID 22, line 281, chars 13915-14014, hits: 0) -- Branch (branch: 11, path: 1) (location: source ID 22, line 281, chars 13915-14014, hits: 0) -- Statement (location: source ID 22, line 281, chars 13949-14014, hits: 0) -- Line (location: source ID 22, line 282, chars 14024-14079, hits: 0) -- Statement (location: source ID 22, line 282, chars 14024-14079, hits: 0) -- Statement (location: source ID 22, line 282, chars 14048-14079, hits: 0) -- Branch (branch: 12, path: 0) (location: source ID 22, line 282, chars 14020-14120, hits: 0) -- Branch (branch: 12, path: 1) (location: source ID 22, line 282, chars 14020-14120, hits: 0) -- Statement (location: source ID 22, line 282, chars 14081-14120, hits: 0) -- Line (location: source ID 22, line 284, chars 14127-14239, hits: 0) -- Statement (location: source ID 22, line 284, chars 14127-14239, hits: 0) -- Line (location: source ID 22, line 286, chars 14246-14290, hits: 0) -- Statement (location: source ID 22, line 286, chars 14246-14290, hits: 0) -- Line (location: source ID 22, line 291, chars 14494-14571, hits: 0) -- Statement (location: source ID 22, line 291, chars 14494-14571, hits: 0) -- Line (location: source ID 22, line 293, chars 14578-14657, hits: 0) -- Statement (location: source ID 22, line 293, chars 14578-14657, hits: 0) -- Line (location: source ID 22, line 294, chars 14663-14695, hits: 0) -- Statement (location: source ID 22, line 294, chars 14663-14695, hits: 0) -- Line (location: source ID 22, line 297, chars 14787-14841, hits: 0) -- Statement (location: source ID 22, line 297, chars 14787-14841, hits: 0) -- Function "_ccipReceive" (location: source ID 22, line 388, chars 18117-20066, hits: 0) -- Line (location: source ID 22, line 394, chars 18471-18598, hits: 0) -- Statement (location: source ID 22, line 394, chars 18471-18598, hits: 0) -- Statement (location: source ID 22, line 394, chars 18538-18598, hits: 0) -- Line (location: source ID 22, line 396, chars 18605-18688, hits: 0) -- Statement (location: source ID 22, line 396, chars 18605-18688, hits: 0) -- Line (location: source ID 22, line 398, chars 18699-18714, hits: 0) -- Statement (location: source ID 22, line 398, chars 18699-18714, hits: 0) -- Branch (branch: 16, path: 0) (location: source ID 22, line 398, chars 18695-19312, hits: 0) -- Branch (branch: 16, path: 1) (location: source ID 22, line 398, chars 18695-19312, hits: 0) -- Line (location: source ID 22, line 399, chars 18724-18839, hits: 0) -- Statement (location: source ID 22, line 399, chars 18724-18839, hits: 0) -- Statement (location: source ID 22, line 399, chars 18766-18839, hits: 0) -- Line (location: source ID 22, line 401, chars 18852-18977, hits: 0) -- Statement (location: source ID 22, line 401, chars 18852-18977, hits: 0) -- Statement (location: source ID 22, line 401, chars 18947-18977, hits: 0) -- Branch (branch: 17, path: 0) (location: source ID 22, line 401, chars 18848-19174, hits: 0) -- Branch (branch: 17, path: 1) (location: source ID 22, line 401, chars 18848-19174, hits: 0) -- Line (location: source ID 22, line 402, chars 18989-19032, hits: 0) -- Statement (location: source ID 22, line 402, chars 18989-19032, hits: 0) -- Line (location: source ID 22, line 406, chars 19252-19297, hits: 0) -- Statement (location: source ID 22, line 406, chars 19252-19297, hits: 0) -- Line (location: source ID 22, line 408, chars 19322-19354, hits: 0) -- Statement (location: source ID 22, line 408, chars 19322-19354, hits: 0) -- Statement (location: source ID 22, line 408, chars 19344-19354, hits: 0) -- Branch (branch: 18, path: 0) (location: source ID 22, line 408, chars 19318-19798, hits: 0) -- Branch (branch: 18, path: 1) (location: source ID 22, line 408, chars 19318-19798, hits: 0) -- Line (location: source ID 22, line 409, chars 19364-19456, hits: 0) -- Statement (location: source ID 22, line 409, chars 19364-19456, hits: 0) -- Line (location: source ID 22, line 412, chars 19515-19699, hits: 0) -- Statement (location: source ID 22, line 412, chars 19515-19699, hits: 0) -- Line (location: source ID 22, line 416, chars 19708-19791, hits: 0) -- Statement (location: source ID 22, line 416, chars 19708-19791, hits: 0) -- Line (location: source ID 22, line 419, chars 19804-20061, hits: 0) -- Statement (location: source ID 22, line 419, chars 19804-20061, hits: 0) -- Branch (branch: 19, path: 1) (location: source ID 22, line 441, chars 20679-20810, hits: 0) -- Statement (location: source ID 22, line 441, chars 20728-20810, hits: 0) -- Function "fulfillRequest" (location: source ID 22, line 495, chars 22805-23639, hits: 0) -- Line (location: source ID 22, line 496, chars 22913-22975, hits: 0) -- Statement (location: source ID 22, line 496, chars 22913-22975, hits: 0) -- Line (location: source ID 22, line 498, chars 22986-23000, hits: 0) -- Statement (location: source ID 22, line 498, chars 22986-23000, hits: 0) -- Branch (branch: 20, path: 0) (location: source ID 22, line 498, chars 22982-23089, hits: 0) -- Branch (branch: 20, path: 1) (location: source ID 22, line 498, chars 22982-23089, hits: 0) -- Line (location: source ID 22, line 499, chars 23010-23068, hits: 0) -- Statement (location: source ID 22, line 499, chars 23010-23068, hits: 0) -- Line (location: source ID 22, line 500, chars 23076-23083, hits: 0) -- Statement (location: source ID 22, line 500, chars 23076-23083, hits: 0) -- Line (location: source ID 22, line 503, chars 23095-23154, hits: 0) -- Statement (location: source ID 22, line 503, chars 23095-23154, hits: 0) -- Statement (location: source ID 22, line 503, chars 23123-23154, hits: 0) -- Line (location: source ID 22, line 504, chars 23160-23227, hits: 0) -- Statement (location: source ID 22, line 504, chars 23160-23227, hits: 0) -- Statement (location: source ID 22, line 504, chars 23182-23227, hits: 0) -- Line (location: source ID 22, line 506, chars 23238-23297, hits: 0) -- Statement (location: source ID 22, line 506, chars 23238-23297, hits: 0) -- Branch (branch: 21, path: 0) (location: source ID 22, line 506, chars 23234-23434, hits: 0) -- Branch (branch: 21, path: 1) (location: source ID 22, line 506, chars 23234-23434, hits: 0) -- Line (location: source ID 22, line 507, chars 23307-23427, hits: 0) -- Statement (location: source ID 22, line 507, chars 23307-23427, hits: 0) -- Line (location: source ID 22, line 508, chars 23444-23508, hits: 0) -- Statement (location: source ID 22, line 508, chars 23444-23508, hits: 0) -- Branch (branch: 22, path: 0) (location: source ID 22, line 508, chars 23440-23635, hits: 0) -- Branch (branch: 22, path: 1) (location: source ID 22, line 508, chars 23440-23635, hits: 0) -- Line (location: source ID 22, line 509, chars 23518-23628, hits: 0) -- Statement (location: source ID 22, line 509, chars 23518-23628, hits: 0) -- Function "_updateDepositInfoAndMintLPTokens" (location: source ID 22, line 529, chars 24419-25297, hits: 0) -- Line (location: source ID 22, line 537, chars 24681-24765, hits: 0) -- Statement (location: source ID 22, line 537, chars 24681-24765, hits: 0) -- Statement (location: source ID 22, line 537, chars 24718-24765, hits: 0) -- Line (location: source ID 22, line 538, chars 24771-24847, hits: 0) -- Statement (location: source ID 22, line 538, chars 24771-24847, hits: 0) -- Statement (location: source ID 22, line 538, chars 24806-24847, hits: 0) -- Line (location: source ID 22, line 542, chars 25003-25240, hits: 0) -- Statement (location: source ID 22, line 542, chars 25003-25240, hits: 0) -- Statement (location: source ID 22, line 542, chars 25028-25240, hits: 0) -- Line (location: source ID 22, line 546, chars 25247-25292, hits: 0) -- Statement (location: source ID 22, line 546, chars 25247-25292, hits: 0) -- Function "_updateUsdcAmountEarned" (location: source ID 22, line 559, chars 25860-27330, hits: 0) -- Line (location: source ID 22, line 560, chars 26016-26066, hits: 0) -- Statement (location: source ID 22, line 560, chars 26016-26066, hits: 0) -- Line (location: source ID 22, line 561, chars 26072-26174, hits: 0) -- Statement (location: source ID 22, line 561, chars 26072-26174, hits: 0) -- Statement (location: source ID 22, line 561, chars 26105-26174, hits: 0) -- Statement (location: source ID 22, line 561, chars 26105-26159, hits: 0) -- Statement (location: source ID 22, line 561, chars 26128-26159, hits: 0) -- Line (location: source ID 22, line 564, chars 26251-26416, hits: 0) -- Statement (location: source ID 22, line 564, chars 26251-26416, hits: 0) -- Statement (location: source ID 22, line 564, chars 26278-26416, hits: 0) -- Line (location: source ID 22, line 567, chars 26423-26511, hits: 0) -- Statement (location: source ID 22, line 567, chars 26423-26511, hits: 0) -- Statement (location: source ID 22, line 567, chars 26466-26511, hits: 0) -- Line (location: source ID 22, line 569, chars 26518-27044, hits: 0) -- Statement (location: source ID 22, line 569, chars 26518-27044, hits: 0) -- Statement (location: source ID 22, line 569, chars 26564-27044, hits: 0) -- Line (location: source ID 22, line 578, chars 27051-27147, hits: 0) -- Statement (location: source ID 22, line 578, chars 27051-27147, hits: 0) -- Line (location: source ID 22, line 580, chars 27154-27209, hits: 0) -- Statement (location: source ID 22, line 580, chars 27154-27209, hits: 0) -- Line (location: source ID 22, line 581, chars 27215-27268, hits: 0) -- Statement (location: source ID 22, line 581, chars 27215-27268, hits: 0) -- Line (location: source ID 22, line 583, chars 27275-27325, hits: 0) -- Statement (location: source ID 22, line 583, chars 27275-27325, hits: 0) -- Function "_convertToLPTokenDecimals" (location: source ID 22, line 662, chars 31273-31455, hits: 0) -- Line (location: source ID 22, line 663, chars 31383-31450, hits: 0) -- Statement (location: source ID 22, line 663, chars 31383-31450, hits: 0) -- Function "_convertToUSDCTokenDecimals" (location: source ID 22, line 671, chars 31630-31810, hits: 0) -- Line (location: source ID 22, line 672, chars 31740-31805, hits: 0) -- Statement (location: source ID 22, line 672, chars 31740-31805, hits: 0) -- Function "getMaxCap" (location: source ID 22, line 675, chars 31814-31908, hits: 0) -- Line (location: source ID 22, line 676, chars 31881-31903, hits: 0) -- Statement (location: source ID 22, line 676, chars 31881-31903, hits: 0) -- Function "getUsdcInUse" (location: source ID 22, line 679, chars 31912-32015, hits: 0) -- Line (location: source ID 22, line 680, chars 31985-32010, hits: 0) -- Statement (location: source ID 22, line 680, chars 31985-32010, hits: 0) -- Function "deletePendingWithdrawRequest" (location: source ID 22, line 684, chars 32063-32219, hits: 0) -- Line (location: source ID 22, line 685, chars 32162-32214, hits: 0) -- Statement (location: source ID 22, line 685, chars 32162-32214, hits: 0) \ No newline at end of file diff --git a/packages/foundry/coverageTwo.txt b/packages/foundry/coverageTwo.txt new file mode 100644 index 000000000..266625301 --- /dev/null +++ b/packages/foundry/coverageTwo.txt @@ -0,0 +1,520 @@ +Uncovered for ../hardhat/contracts/ConceroAutomation.sol: + - Function "" (location: source ID 0, line 101, chars 5389-5741, hits: 0) + - Line (location: source ID 0, line 109, chars 5603-5619, hits: 0) + - Statement (location: source ID 0, line 109, chars 5603-5619, hits: 0) + - Line (location: source ID 0, line 110, chars 5625-5659, hits: 0) + - Statement (location: source ID 0, line 110, chars 5625-5659, hits: 0) + - Line (location: source ID 0, line 111, chars 5665-5699, hits: 0) + - Statement (location: source ID 0, line 111, chars 5665-5699, hits: 0) + - Line (location: source ID 0, line 112, chars 5705-5736, hits: 0) + - Statement (location: source ID 0, line 112, chars 5705-5736, hits: 0) + - Function "deleteRequest" (location: source ID 0, line 199, chars 9003-9484, hits: 0) + - Line (location: source ID 0, line 200, chars 9079-9139, hits: 0) + - Statement (location: source ID 0, line 200, chars 9079-9139, hits: 0) + - Line (location: source ID 0, line 202, chars 9151-9160, hits: 0) + - Statement (location: source ID 0, line 202, chars 9151-9160, hits: 0) + - Statement (location: source ID 0, line 202, chars 9162-9180, hits: 0) + - Statement (location: source ID 0, line 202, chars 9182-9185, hits: 0) + - Line (location: source ID 0, line 203, chars 9199-9252, hits: 0) + - Statement (location: source ID 0, line 203, chars 9199-9252, hits: 0) + - Branch (branch: 2, path: 0) (location: source ID 0, line 203, chars 9195-9420, hits: 0) + - Branch (branch: 2, path: 1) (location: source ID 0, line 203, chars 9195-9420, hits: 0) + - Line (location: source ID 0, line 204, chars 9264-9367, hits: 0) + - Statement (location: source ID 0, line 204, chars 9264-9367, hits: 0) + - Line (location: source ID 0, line 205, chars 9377-9411, hits: 0) + - Statement (location: source ID 0, line 205, chars 9377-9411, hits: 0) + - Line (location: source ID 0, line 209, chars 9432-9479, hits: 0) + - Statement (location: source ID 0, line 209, chars 9432-9479, hits: 0) + - Function "fulfillRequest" (location: source ID 0, line 263, chars 11652-12643, hits: 0) + - Line (location: source ID 0, line 264, chars 11760-11839, hits: 0) + - Statement (location: source ID 0, line 264, chars 11760-11839, hits: 0) + - Line (location: source ID 0, line 265, chars 11845-11906, hits: 0) + - Statement (location: source ID 0, line 265, chars 11845-11906, hits: 0) + - Line (location: source ID 0, line 267, chars 11917-11931, hits: 0) + - Statement (location: source ID 0, line 267, chars 11917-11931, hits: 0) + - Branch (branch: 5, path: 0) (location: source ID 0, line 267, chars 11913-12234, hits: 0) + - Branch (branch: 5, path: 1) (location: source ID 0, line 267, chars 11913-12234, hits: 0) + - Line (location: source ID 0, line 268, chars 11941-11978, hits: 0) + - Statement (location: source ID 0, line 268, chars 11941-11978, hits: 0) + - Line (location: source ID 0, line 269, chars 11986-12038, hits: 0) + - Statement (location: source ID 0, line 269, chars 11986-12038, hits: 0) + - Line (location: source ID 0, line 274, chars 12240-12286, hits: 0) + - Statement (location: source ID 0, line 274, chars 12240-12286, hits: 0) + - Line (location: source ID 0, line 276, chars 12293-12353, hits: 0) + - Statement (location: source ID 0, line 276, chars 12293-12353, hits: 0) + - Line (location: source ID 0, line 278, chars 12365-12374, hits: 0) + - Statement (location: source ID 0, line 278, chars 12365-12374, hits: 0) + - Statement (location: source ID 0, line 278, chars 12376-12394, hits: 0) + - Statement (location: source ID 0, line 278, chars 12396-12399, hits: 0) + - Line (location: source ID 0, line 279, chars 12413-12465, hits: 0) + - Statement (location: source ID 0, line 279, chars 12413-12465, hits: 0) + - Branch (branch: 6, path: 0) (location: source ID 0, line 279, chars 12409-12633, hits: 0) + - Branch (branch: 6, path: 1) (location: source ID 0, line 279, chars 12409-12633, hits: 0) + - Line (location: source ID 0, line 280, chars 12477-12580, hits: 0) + - Statement (location: source ID 0, line 280, chars 12477-12580, hits: 0) + - Line (location: source ID 0, line 281, chars 12590-12624, hits: 0) + - Statement (location: source ID 0, line 281, chars 12590-12624, hits: 0) + +Uncovered for ../hardhat/contracts/ConceroBridge.sol: + - Function "" (location: source ID 1, line 51, chars 2614-2926, hits: 0) + - Branch (branch: 1, path: 1) (location: source ID 1, line 78, chars 3981-4110, hits: 0) + - Line (location: source ID 1, line 79, chars 4040-4103, hits: 0) + - Statement (location: source ID 1, line 79, chars 4040-4103, hits: 0) + - Function "getSrcTotalFeeInUsdc" (location: source ID 1, line 169, chars 8209-8409, hits: 0) + - Line (location: source ID 1, line 170, chars 8339-8404, hits: 0) + - Statement (location: source ID 1, line 170, chars 8339-8404, hits: 0) + - Statement (location: source ID 1, line 170, chars 8346-8404, hits: 0) + +Uncovered for ../hardhat/contracts/ConceroChildPool.sol: + - Branch (branch: 0, path: 0) (location: source ID 3, line 86, chars 4365-4458, hits: 0) + - Branch (branch: 0, path: 1) (location: source ID 3, line 86, chars 4365-4458, hits: 0) + - Statement (location: source ID 3, line 86, chars 4400-4458, hits: 0) + - Branch (branch: 1, path: 0) (location: source ID 3, line 94, chars 4591-4677, hits: 0) + - Branch (branch: 1, path: 1) (location: source ID 3, line 94, chars 4591-4677, hits: 0) + - Branch (branch: 2, path: 0) (location: source ID 3, line 99, chars 4720-4789, hits: 0) + - Branch (branch: 2, path: 1) (location: source ID 3, line 99, chars 4720-4789, hits: 0) + - Branch (branch: 3, path: 1) (location: source ID 3, line 109, chars 5081-5196, hits: 0) + - Statement (location: source ID 3, line 109, chars 5147-5196, hits: 0) + - Function "" (location: source ID 3, line 118, chars 5485-5838, hits: 0) + - Line (location: source ID 3, line 126, chars 5673-5706, hits: 0) + - Statement (location: source ID 3, line 126, chars 5673-5706, hits: 0) + - Line (location: source ID 3, line 127, chars 5712-5738, hits: 0) + - Statement (location: source ID 3, line 127, chars 5712-5738, hits: 0) + - Line (location: source ID 3, line 128, chars 5744-5783, hits: 0) + - Statement (location: source ID 3, line 128, chars 5744-5783, hits: 0) + - Line (location: source ID 3, line 129, chars 5789-5811, hits: 0) + - Statement (location: source ID 3, line 129, chars 5789-5811, hits: 0) + - Line (location: source ID 3, line 130, chars 5817-5833, hits: 0) + - Statement (location: source ID 3, line 130, chars 5817-5833, hits: 0) + - Branch (branch: 4, path: 0) (location: source ID 3, line 144, chars 6357-6447, hits: 0) + - Line (location: source ID 3, line 145, chars 6453-6513, hits: 0) + - Statement (location: source ID 3, line 145, chars 6453-6513, hits: 0) + - Function "distributeLiquidity" (location: source ID 3, line 153, chars 6745-7010, hits: 0) + - Line (location: source ID 3, line 154, chars 6861-6905, hits: 0) + - Statement (location: source ID 3, line 154, chars 6861-6905, hits: 0) + - Statement (location: source ID 3, line 154, chars 6895-6905, hits: 0) + - Branch (branch: 5, path: 0) (location: source ID 3, line 154, chars 6857-6947, hits: 0) + - Branch (branch: 5, path: 1) (location: source ID 3, line 154, chars 6857-6947, hits: 0) + - Statement (location: source ID 3, line 154, chars 6907-6947, hits: 0) + - Line (location: source ID 3, line 155, chars 6953-7005, hits: 0) + - Statement (location: source ID 3, line 155, chars 6953-7005, hits: 0) + - Function "liquidatePool" (location: source ID 3, line 163, chars 7302-7876, hits: 0) + - Line (location: source ID 3, line 164, chars 7364-7415, hits: 0) + - Statement (location: source ID 3, line 164, chars 7364-7415, hits: 0) + - Line (location: source ID 3, line 165, chars 7425-7448, hits: 0) + - Statement (location: source ID 3, line 165, chars 7425-7448, hits: 0) + - Branch (branch: 6, path: 0) (location: source ID 3, line 165, chars 7421-7501, hits: 0) + - Branch (branch: 6, path: 1) (location: source ID 3, line 165, chars 7421-7501, hits: 0) + - Statement (location: source ID 3, line 165, chars 7450-7501, hits: 0) + - Line (location: source ID 3, line 167, chars 7508-7594, hits: 0) + - Statement (location: source ID 3, line 167, chars 7508-7594, hits: 0) + - Statement (location: source ID 3, line 167, chars 7541-7594, hits: 0) + - Line (location: source ID 3, line 169, chars 7606-7615, hits: 0) + - Statement (location: source ID 3, line 169, chars 7606-7615, hits: 0) + - Statement (location: source ID 3, line 169, chars 7617-7634, hits: 0) + - Line (location: source ID 3, line 171, chars 7756-7826, hits: 0) + - Statement (location: source ID 3, line 171, chars 7756-7826, hits: 0) + - Line (location: source ID 3, line 173, chars 7854-7857, hits: 0) + - Statement (location: source ID 3, line 173, chars 7854-7857, hits: 0) + - Branch (branch: 8, path: 1) (location: source ID 3, line 188, chars 8463-8563, hits: 0) + - Function "setPools" (location: source ID 3, line 224, chars 9952-10325, hits: 0) + - Line (location: source ID 3, line 225, chars 10053-10115, hits: 0) + - Statement (location: source ID 3, line 225, chars 10053-10115, hits: 0) + - Statement (location: source ID 3, line 225, chars 10053-10092, hits: 0) + - Statement (location: source ID 3, line 225, chars 10096-10115, hits: 0) + - Statement (location: source ID 3, line 225, chars 10105-10115, hits: 0) + - Branch (branch: 11, path: 0) (location: source ID 3, line 225, chars 10049-10157, hits: 0) + - Branch (branch: 11, path: 1) (location: source ID 3, line 225, chars 10049-10157, hits: 0) + - Statement (location: source ID 3, line 225, chars 10117-10157, hits: 0) + - Line (location: source ID 3, line 227, chars 10164-10205, hits: 0) + - Statement (location: source ID 3, line 227, chars 10164-10205, hits: 0) + - Line (location: source ID 3, line 228, chars 10211-10249, hits: 0) + - Statement (location: source ID 3, line 228, chars 10211-10249, hits: 0) + - Line (location: source ID 3, line 230, chars 10256-10320, hits: 0) + - Statement (location: source ID 3, line 230, chars 10256-10320, hits: 0) + - Function "removePools" (location: source ID 3, line 237, chars 10489-10978, hits: 0) + - Line (location: source ID 3, line 239, chars 10580-10589, hits: 0) + - Statement (location: source ID 3, line 239, chars 10580-10589, hits: 0) + - Statement (location: source ID 3, line 239, chars 10591-10622, hits: 0) + - Line (location: source ID 3, line 240, chars 10638-10679, hits: 0) + - Statement (location: source ID 3, line 240, chars 10638-10679, hits: 0) + - Branch (branch: 12, path: 0) (location: source ID 3, line 240, chars 10634-10862, hits: 0) + - Branch (branch: 12, path: 1) (location: source ID 3, line 240, chars 10634-10862, hits: 0) + - Line (location: source ID 3, line 241, chars 10691-10770, hits: 0) + - Statement (location: source ID 3, line 241, chars 10691-10770, hits: 0) + - Line (location: source ID 3, line 242, chars 10780-10806, hits: 0) + - Statement (location: source ID 3, line 242, chars 10780-10806, hits: 0) + - Line (location: source ID 3, line 243, chars 10816-10853, hits: 0) + - Statement (location: source ID 3, line 243, chars 10816-10853, hits: 0) + - Line (location: source ID 3, line 246, chars 10889-10892, hits: 0) + - Statement (location: source ID 3, line 246, chars 10889-10892, hits: 0) + - Line (location: source ID 3, line 250, chars 10913-10973, hits: 0) + - Statement (location: source ID 3, line 250, chars 10913-10973, hits: 0) + - Branch (branch: 13, path: 1) (location: source ID 3, line 269, chars 11802-12418, hits: 0) + - Branch (branch: 14, path: 1) (location: source ID 3, line 272, chars 11955-12280, hits: 0) + - Line (location: source ID 3, line 277, chars 12358-12403, hits: 0) + - Statement (location: source ID 3, line 277, chars 12358-12403, hits: 0) + - Function "_ccipSend" (location: source ID 3, line 297, chars 13217-14686, hits: 0) + - Line (location: source ID 3, line 298, chars 13380-13421, hits: 0) + - Statement (location: source ID 3, line 298, chars 13380-13421, hits: 0) + - Statement (location: source ID 3, line 298, chars 13390-13421, hits: 0) + - Branch (branch: 15, path: 0) (location: source ID 3, line 298, chars 13376-13468, hits: 0) + - Branch (branch: 15, path: 1) (location: source ID 3, line 298, chars 13376-13468, hits: 0) + - Statement (location: source ID 3, line 298, chars 13423-13468, hits: 0) + - Line (location: source ID 3, line 300, chars 13475-13551, hits: 0) + - Statement (location: source ID 3, line 300, chars 13475-13551, hits: 0) + - Statement (location: source ID 3, line 300, chars 13521-13551, hits: 0) + - Line (location: source ID 3, line 302, chars 13558-13665, hits: 0) + - Statement (location: source ID 3, line 302, chars 13558-13665, hits: 0) + - Statement (location: source ID 3, line 302, chars 13601-13665, hits: 0) + - Line (location: source ID 3, line 304, chars 13672-13701, hits: 0) + - Statement (location: source ID 3, line 304, chars 13672-13701, hits: 0) + - Line (location: source ID 3, line 306, chars 13708-14146, hits: 0) + - Statement (location: source ID 3, line 306, chars 13708-14146, hits: 0) + - Statement (location: source ID 3, line 306, chars 13754-14146, hits: 0) + - Line (location: source ID 3, line 314, chars 14153-14234, hits: 0) + - Statement (location: source ID 3, line 314, chars 14153-14234, hits: 0) + - Statement (location: source ID 3, line 314, chars 14168-14234, hits: 0) + - Line (location: source ID 3, line 316, chars 14245-14288, hits: 0) + - Statement (location: source ID 3, line 316, chars 14245-14288, hits: 0) + - Statement (location: source ID 3, line 316, chars 14252-14288, hits: 0) + - Branch (branch: 16, path: 0) (location: source ID 3, line 316, chars 14241-14378, hits: 0) + - Branch (branch: 16, path: 1) (location: source ID 3, line 316, chars 14241-14378, hits: 0) + - Statement (location: source ID 3, line 316, chars 14290-14378, hits: 0) + - Line (location: source ID 3, line 318, chars 14385-14422, hits: 0) + - Statement (location: source ID 3, line 318, chars 14385-14422, hits: 0) + - Line (location: source ID 3, line 319, chars 14428-14467, hits: 0) + - Statement (location: source ID 3, line 319, chars 14428-14467, hits: 0) + - Line (location: source ID 3, line 321, chars 14474-14594, hits: 0) + - Statement (location: source ID 3, line 321, chars 14474-14594, hits: 0) + - Line (location: source ID 3, line 323, chars 14601-14681, hits: 0) + - Statement (location: source ID 3, line 323, chars 14601-14681, hits: 0) + +Uncovered for ../hardhat/contracts/ConceroParentPool.sol: +- Function "onlyAllowlistedSenderAndChainSelector" (location: source ID 6, line 146, chars 8902-9123, hits: 0) +- Line (location: source ID 6, line 147, chars 8999-9059, hits: 0) +- Statement (location: source ID 6, line 147, chars 8999-9059, hits: 0) +- Branch (branch: 0, path: 0) (location: source ID 6, line 147, chars 8995-9111, hits: 0) +- Branch (branch: 0, path: 1) (location: source ID 6, line 147, chars 8995-9111, hits: 0) +- Statement (location: source ID 6, line 147, chars 9061-9111, hits: 0) +- Branch (branch: 1, path: 1) (location: source ID 6, line 155, chars 9252-9347, hits: 0) +- Branch (branch: 2, path: 1) (location: source ID 6, line 160, chars 9390-9460, hits: 0) +- Branch (branch: 3, path: 1) (location: source ID 6, line 168, chars 9593-9680, hits: 0) +- Statement (location: source ID 6, line 168, chars 9631-9680, hits: 0) +- Function "" (location: source ID 6, line 177, chars 9969-10617, hits: 0) +- Line (location: source ID 6, line 190, chars 10312-10328, hits: 0) +- Statement (location: source ID 6, line 190, chars 10312-10328, hits: 0) +- Line (location: source ID 6, line 191, chars 10334-10368, hits: 0) +- Statement (location: source ID 6, line 191, chars 10334-10368, hits: 0) +- Line (location: source ID 6, line 192, chars 10374-10402, hits: 0) +- Statement (location: source ID 6, line 192, chars 10374-10402, hits: 0) +- Line (location: source ID 6, line 193, chars 10408-10447, hits: 0) +- Statement (location: source ID 6, line 193, chars 10408-10447, hits: 0) +- Line (location: source ID 6, line 194, chars 10453-10475, hits: 0) +- Statement (location: source ID 6, line 194, chars 10453-10475, hits: 0) +- Line (location: source ID 6, line 195, chars 10481-10505, hits: 0) +- Statement (location: source ID 6, line 195, chars 10481-10505, hits: 0) +- Line (location: source ID 6, line 196, chars 10511-10556, hits: 0) +- Statement (location: source ID 6, line 196, chars 10511-10556, hits: 0) +- Line (location: source ID 6, line 197, chars 10562-10590, hits: 0) +- Statement (location: source ID 6, line 197, chars 10562-10590, hits: 0) +- Line (location: source ID 6, line 198, chars 10596-10612, hits: 0) +- Statement (location: source ID 6, line 198, chars 10596-10612, hits: 0) +- Branch (branch: 6, path: 1) (location: source ID 6, line 215, chars 11370-11494, hits: 0) +- Line (location: source ID 6, line 217, chars 11501-11538, hits: 0) +- Statement (location: source ID 6, line 217, chars 11501-11538, hits: 0) +- Line (location: source ID 6, line 219, chars 11545-11592, hits: 0) +- Statement (location: source ID 6, line 219, chars 11545-11592, hits: 0) +- Branch (branch: 8, path: 1) (location: source ID 6, line 228, chars 11897-12051, hits: 0) +- Branch (branch: 10, path: 1) (location: source ID 6, line 265, chars 13506-13596, hits: 0) +- Branch (branch: 11, path: 1) (location: source ID 6, line 266, chars 13602-13717, hits: 0) +- Statement (location: source ID 6, line 266, chars 13662-13717, hits: 0) +- Function "completeWithdrawal" (location: source ID 6, line 291, chars 14547-15637, hits: 0) +- Line (location: source ID 6, line 292, chars 14600-14678, hits: 0) +- Statement (location: source ID 6, line 292, chars 14600-14678, hits: 0) +- Line (location: source ID 6, line 294, chars 14689-14717, hits: 0) +- Statement (location: source ID 6, line 294, chars 14689-14717, hits: 0) +- Branch (branch: 12, path: 0) (location: source ID 6, line 294, chars 14685-14791, hits: 0) +- Branch (branch: 12, path: 1) (location: source ID 6, line 294, chars 14685-14791, hits: 0) +- Statement (location: source ID 6, line 294, chars 14719-14791, hits: 0) +- Line (location: source ID 6, line 295, chars 14801-14856, hits: 0) +- Statement (location: source ID 6, line 295, chars 14801-14856, hits: 0) +- Statement (location: source ID 6, line 295, chars 14825-14856, hits: 0) +- Branch (branch: 13, path: 0) (location: source ID 6, line 295, chars 14797-14904, hits: 0) +- Branch (branch: 13, path: 1) (location: source ID 6, line 295, chars 14797-14904, hits: 0) +- Statement (location: source ID 6, line 295, chars 14858-14904, hits: 0) +- Line (location: source ID 6, line 297, chars 14911-15023, hits: 0) +- Statement (location: source ID 6, line 297, chars 14911-15023, hits: 0) +- Line (location: source ID 6, line 299, chars 15030-15074, hits: 0) +- Statement (location: source ID 6, line 299, chars 15030-15074, hits: 0) +- Line (location: source ID 6, line 304, chars 15278-15362, hits: 0) +- Statement (location: source ID 6, line 304, chars 15278-15362, hits: 0) +- Line (location: source ID 6, line 306, chars 15369-15448, hits: 0) +- Statement (location: source ID 6, line 306, chars 15369-15448, hits: 0) +- Line (location: source ID 6, line 307, chars 15454-15486, hits: 0) +- Statement (location: source ID 6, line 307, chars 15454-15486, hits: 0) +- Line (location: source ID 6, line 310, chars 15578-15632, hits: 0) +- Statement (location: source ID 6, line 310, chars 15578-15632, hits: 0) +- Branch (branch: 14, path: 0) (location: source ID 6, line 319, chars 15976-16067, hits: 0) +- Line (location: source ID 6, line 320, chars 16073-16113, hits: 0) +- Statement (location: source ID 6, line 320, chars 16073-16113, hits: 0) +- Function "_ccipReceive" (location: source ID 6, line 453, chars 21125-23075, hits: 0) +- Line (location: source ID 6, line 459, chars 21479-21606, hits: 0) +- Statement (location: source ID 6, line 459, chars 21479-21606, hits: 0) +- Statement (location: source ID 6, line 459, chars 21546-21606, hits: 0) +- Line (location: source ID 6, line 461, chars 21613-21696, hits: 0) +- Statement (location: source ID 6, line 461, chars 21613-21696, hits: 0) +- Line (location: source ID 6, line 463, chars 21707-21722, hits: 0) +- Statement (location: source ID 6, line 463, chars 21707-21722, hits: 0) +- Branch (branch: 19, path: 0) (location: source ID 6, line 463, chars 21703-22320, hits: 0) +- Branch (branch: 19, path: 1) (location: source ID 6, line 463, chars 21703-22320, hits: 0) +- Line (location: source ID 6, line 464, chars 21732-21847, hits: 0) +- Statement (location: source ID 6, line 464, chars 21732-21847, hits: 0) +- Statement (location: source ID 6, line 464, chars 21774-21847, hits: 0) +- Line (location: source ID 6, line 466, chars 21860-21985, hits: 0) +- Statement (location: source ID 6, line 466, chars 21860-21985, hits: 0) +- Statement (location: source ID 6, line 466, chars 21955-21985, hits: 0) +- Branch (branch: 20, path: 0) (location: source ID 6, line 466, chars 21856-22182, hits: 0) +- Branch (branch: 20, path: 1) (location: source ID 6, line 466, chars 21856-22182, hits: 0) +- Line (location: source ID 6, line 467, chars 21997-22040, hits: 0) +- Statement (location: source ID 6, line 467, chars 21997-22040, hits: 0) +- Line (location: source ID 6, line 471, chars 22260-22305, hits: 0) +- Statement (location: source ID 6, line 471, chars 22260-22305, hits: 0) +- Line (location: source ID 6, line 473, chars 22330-22362, hits: 0) +- Statement (location: source ID 6, line 473, chars 22330-22362, hits: 0) +- Statement (location: source ID 6, line 473, chars 22352-22362, hits: 0) +- Branch (branch: 21, path: 0) (location: source ID 6, line 473, chars 22326-22800, hits: 0) +- Branch (branch: 21, path: 1) (location: source ID 6, line 473, chars 22326-22800, hits: 0) +- Line (location: source ID 6, line 474, chars 22372-22458, hits: 0) +- Statement (location: source ID 6, line 474, chars 22372-22458, hits: 0) +- Line (location: source ID 6, line 477, chars 22517-22701, hits: 0) +- Statement (location: source ID 6, line 477, chars 22517-22701, hits: 0) +- Line (location: source ID 6, line 481, chars 22710-22793, hits: 0) +- Statement (location: source ID 6, line 481, chars 22710-22793, hits: 0) +- Line (location: source ID 6, line 484, chars 22806-23070, hits: 0) +- Statement (location: source ID 6, line 484, chars 22806-23070, hits: 0) +- Branch (branch: 22, path: 1) (location: source ID 6, line 517, chars 24020-24158, hits: 0) +- Statement (location: source ID 6, line 517, chars 24069-24158, hits: 0) +- Function "fulfillRequest" (location: source ID 6, line 562, chars 26115-26931, hits: 0) +- Line (location: source ID 6, line 563, chars 26223-26279, hits: 0) +- Statement (location: source ID 6, line 563, chars 26223-26279, hits: 0) +- Line (location: source ID 6, line 565, chars 26290-26304, hits: 0) +- Statement (location: source ID 6, line 565, chars 26290-26304, hits: 0) +- Branch (branch: 23, path: 0) (location: source ID 6, line 565, chars 26286-26393, hits: 0) +- Branch (branch: 23, path: 1) (location: source ID 6, line 565, chars 26286-26393, hits: 0) +- Line (location: source ID 6, line 566, chars 26314-26372, hits: 0) +- Statement (location: source ID 6, line 566, chars 26314-26372, hits: 0) +- Line (location: source ID 6, line 567, chars 26380-26387, hits: 0) +- Statement (location: source ID 6, line 567, chars 26380-26387, hits: 0) +- Line (location: source ID 6, line 570, chars 26399-26458, hits: 0) +- Statement (location: source ID 6, line 570, chars 26399-26458, hits: 0) +- Statement (location: source ID 6, line 570, chars 26427-26458, hits: 0) +- Line (location: source ID 6, line 571, chars 26464-26531, hits: 0) +- Statement (location: source ID 6, line 571, chars 26464-26531, hits: 0) +- Statement (location: source ID 6, line 571, chars 26486-26531, hits: 0) +- Line (location: source ID 6, line 573, chars 26542-26595, hits: 0) +- Statement (location: source ID 6, line 573, chars 26542-26595, hits: 0) +- Branch (branch: 24, path: 0) (location: source ID 6, line 573, chars 26538-26732, hits: 0) +- Branch (branch: 24, path: 1) (location: source ID 6, line 573, chars 26538-26732, hits: 0) +- Line (location: source ID 6, line 574, chars 26605-26725, hits: 0) +- Statement (location: source ID 6, line 574, chars 26605-26725, hits: 0) +- Line (location: source ID 6, line 575, chars 26742-26800, hits: 0) +- Statement (location: source ID 6, line 575, chars 26742-26800, hits: 0) +- Branch (branch: 25, path: 0) (location: source ID 6, line 575, chars 26738-26927, hits: 0) +- Branch (branch: 25, path: 1) (location: source ID 6, line 575, chars 26738-26927, hits: 0) +- Line (location: source ID 6, line 576, chars 26810-26920, hits: 0) +- Statement (location: source ID 6, line 576, chars 26810-26920, hits: 0) +- Function "_updateDepositInfoAndMintLPTokens" (location: source ID 6, line 592, chars 27521-28399, hits: 0) +- Line (location: source ID 6, line 600, chars 27783-27867, hits: 0) +- Statement (location: source ID 6, line 600, chars 27783-27867, hits: 0) +- Statement (location: source ID 6, line 600, chars 27820-27867, hits: 0) +- Line (location: source ID 6, line 601, chars 27873-27949, hits: 0) +- Statement (location: source ID 6, line 601, chars 27873-27949, hits: 0) +- Statement (location: source ID 6, line 601, chars 27908-27949, hits: 0) +- Line (location: source ID 6, line 605, chars 28105-28342, hits: 0) +- Statement (location: source ID 6, line 605, chars 28105-28342, hits: 0) +- Statement (location: source ID 6, line 605, chars 28130-28342, hits: 0) +- Line (location: source ID 6, line 609, chars 28349-28394, hits: 0) +- Statement (location: source ID 6, line 609, chars 28349-28394, hits: 0) +- Function "_updateUsdcAmountEarned" (location: source ID 6, line 622, chars 28962-30428, hits: 0) +- Line (location: source ID 6, line 623, chars 29118-29169, hits: 0) +- Statement (location: source ID 6, line 623, chars 29118-29169, hits: 0) +- Line (location: source ID 6, line 624, chars 29175-29277, hits: 0) +- Statement (location: source ID 6, line 624, chars 29175-29277, hits: 0) +- Statement (location: source ID 6, line 624, chars 29208-29277, hits: 0) +- Statement (location: source ID 6, line 624, chars 29208-29262, hits: 0) +- Statement (location: source ID 6, line 624, chars 29231-29262, hits: 0) +- Line (location: source ID 6, line 627, chars 29354-29519, hits: 0) +- Statement (location: source ID 6, line 627, chars 29354-29519, hits: 0) +- Statement (location: source ID 6, line 627, chars 29381-29519, hits: 0) +- Line (location: source ID 6, line 630, chars 29526-29614, hits: 0) +- Statement (location: source ID 6, line 630, chars 29526-29614, hits: 0) +- Statement (location: source ID 6, line 630, chars 29569-29614, hits: 0) +- Line (location: source ID 6, line 632, chars 29621-30135, hits: 0) +- Statement (location: source ID 6, line 632, chars 29621-30135, hits: 0) +- Statement (location: source ID 6, line 632, chars 29661-30135, hits: 0) +- Line (location: source ID 6, line 641, chars 30142-30238, hits: 0) +- Statement (location: source ID 6, line 641, chars 30142-30238, hits: 0) +- Line (location: source ID 6, line 643, chars 30245-30300, hits: 0) +- Statement (location: source ID 6, line 643, chars 30245-30300, hits: 0) +- Line (location: source ID 6, line 644, chars 30306-30359, hits: 0) +- Statement (location: source ID 6, line 644, chars 30306-30359, hits: 0) +- Line (location: source ID 6, line 646, chars 30366-30423, hits: 0) +- Statement (location: source ID 6, line 646, chars 30366-30423, hits: 0) +- Function "_convertToLPTokenDecimals" (location: source ID 6, line 723, chars 34272-34454, hits: 0) +- Line (location: source ID 6, line 724, chars 34382-34449, hits: 0) +- Statement (location: source ID 6, line 724, chars 34382-34449, hits: 0) +- Function "_convertToUSDCTokenDecimals" (location: source ID 6, line 732, chars 34629-34809, hits: 0) +- Line (location: source ID 6, line 733, chars 34739-34804, hits: 0) +- Statement (location: source ID 6, line 733, chars 34739-34804, hits: 0) +- Function "getMaxCap" (location: source ID 6, line 740, chars 34997-35091, hits: 0) +- Line (location: source ID 6, line 741, chars 35064-35086, hits: 0) +- Statement (location: source ID 6, line 741, chars 35064-35086, hits: 0) +- Function "getUsdcInUse" (location: source ID 6, line 744, chars 35095-35198, hits: 0) +- Line (location: source ID 6, line 745, chars 35168-35193, hits: 0) +- Statement (location: source ID 6, line 745, chars 35168-35193, hits: 0) +- Line (location: source ID 6, line 767, chars 35869-35881, hits: 0) +- Statement (location: source ID 6, line 767, chars 35869-35881, hits: 0) + +Uncovered for ../hardhat/contracts/DexSwap.sol: + - Function "" (location: source ID 8, line 53, chars 2304-2394, hits: 0) + - Line (location: source ID 8, line 54, chars 2353-2369, hits: 0) + - Statement (location: source ID 8, line 54, chars 2353-2369, hits: 0) + - Line (location: source ID 8, line 55, chars 2375-2389, hits: 0) + - Statement (location: source ID 8, line 55, chars 2375-2389, hits: 0) + - Branch (branch: 1, path: 1) (location: source ID 8, line 68, chars 2928-3131, hits: 0) + - Statement (location: source ID 8, line 69, chars 3042-3092, hits: 0) + - Branch (branch: 2, path: 1) (location: source ID 8, line 69, chars 2988-3122, hits: 0) + - Statement (location: source ID 8, line 69, chars 3094-3122, hits: 0) + - Line (location: source ID 8, line 75, chars 3326-3380, hits: 0) + - Statement (location: source ID 8, line 75, chars 3326-3380, hits: 0) + - Statement (location: source ID 8, line 75, chars 3326-3349, hits: 0) + - Statement (location: source ID 8, line 75, chars 3331-3349, hits: 0) + - Statement (location: source ID 8, line 75, chars 3367-3380, hits: 0) + - Statement (location: source ID 8, line 201, chars 9139-9169, hits: 0) + - Branch (branch: 26, path: 1) (location: source ID 8, line 201, chars 9101-9695, hits: 0) + - Line (location: source ID 8, line 216, chars 9709-10088, hits: 0) + - Statement (location: source ID 8, line 216, chars 9709-10088, hits: 0) + - Statement (location: source ID 8, line 216, chars 9757-10088, hits: 0) + - Line (location: source ID 8, line 227, chars 10097-10183, hits: 0) + - Statement (location: source ID 8, line 227, chars 10097-10183, hits: 0) + - Line (location: source ID 8, line 229, chars 10192-10240, hits: 0) + - Statement (location: source ID 8, line 229, chars 10192-10240, hits: 0) + - Statement (location: source ID 8, line 274, chars 12210-12240, hits: 0) + - Branch (branch: 33, path: 1) (location: source ID 8, line 274, chars 12172-12635, hits: 0) + - Line (location: source ID 8, line 286, chars 12649-12900, hits: 0) + - Statement (location: source ID 8, line 286, chars 12649-12900, hits: 0) + - Statement (location: source ID 8, line 286, chars 12694-12900, hits: 0) + - Line (location: source ID 8, line 294, chars 12909-12995, hits: 0) + - Statement (location: source ID 8, line 294, chars 12909-12995, hits: 0) + - Line (location: source ID 8, line 296, chars 13004-13049, hits: 0) + - Statement (location: source ID 8, line 296, chars 13004-13049, hits: 0) + - Line (location: source ID 8, line 358, chars 16154-16195, hits: 0) + - Statement (location: source ID 8, line 358, chars 16154-16195, hits: 0) + - Line (location: source ID 8, line 364, chars 16293-16339, hits: 0) + - Statement (location: source ID 8, line 364, chars 16293-16339, hits: 0) + +Uncovered for ../hardhat/contracts/LPToken.sol: + - Function "" (location: source ID 16, line 13, chars 584-792, hits: 0) + - Line (location: source ID 16, line 14, chars 706-750, hits: 0) + - Statement (location: source ID 16, line 14, chars 706-750, hits: 0) + - Line (location: source ID 16, line 15, chars 756-787, hits: 0) + - Statement (location: source ID 16, line 15, chars 756-787, hits: 0) + - Function "mint" (location: source ID 16, line 18, chars 796-895, hits: 0) + - Line (location: source ID 16, line 19, chars 873-890, hits: 0) + - Statement (location: source ID 16, line 19, chars 873-890, hits: 0) + +Uncovered for ../hardhat/contracts/Orchestrator.sol: +- Function "addUnconfirmedTX" (location: source ID 22, line 167, chars 7177-7743, hits: 0) +- Line (location: source ID 22, line 177, chars 7433-7656, hits: 0) +- Statement (location: source ID 22, line 177, chars 7433-7656, hits: 0) +- Statement (location: source ID 22, line 177, chars 7469-7656, hits: 0) +- Line (location: source ID 22, line 180, chars 7666-7682, hits: 0) +- Statement (location: source ID 22, line 180, chars 7666-7682, hits: 0) +- Branch (branch: 15, path: 0) (location: source ID 22, line 180, chars 7662-7738, hits: 0) +- Branch (branch: 15, path: 1) (location: source ID 22, line 180, chars 7662-7738, hits: 0) +- Statement (location: source ID 22, line 180, chars 7684-7738, hits: 0) +- Branch (branch: 17, path: 0) (location: source ID 22, line 192, chars 8142-8228, hits: 0) +- Line (location: source ID 22, line 194, chars 8235-8280, hits: 0) +- Statement (location: source ID 22, line 194, chars 8235-8280, hits: 0) + +- Function "getSrcTotalFeeInUsdcViaDelegateCall" (location: source ID 22, line 197, chars 8289-8753, hits: 0) +- Line (location: source ID 22, line 198, chars 8429-8600, hits: 0) +- Statement (location: source ID 22, line 198, chars 8429-8600, hits: 0) +- Statement (location: source ID 22, line 198, chars 8465-8600, hits: 0) +- Line (location: source ID 22, line 202, chars 8611-8627, hits: 0) +- Statement (location: source ID 22, line 202, chars 8611-8627, hits: 0) +- Branch (branch: 18, path: 0) (location: source ID 22, line 202, chars 8607-8683, hits: 0) +- Branch (branch: 18, path: 1) (location: source ID 22, line 202, chars 8607-8683, hits: 0) +- Statement (location: source ID 22, line 202, chars 8629-8683, hits: 0) +- Line (location: source ID 22, line 204, chars 8690-8748, hits: 0) +- Statement (location: source ID 22, line 204, chars 8690-8748, hits: 0) +- Statement (location: source ID 22, line 204, chars 8697-8748, hits: 0) +- Branch (branch: 19, path: 1) (location: source ID 22, line 212, chars 9012-9069, hits: 0) +- Statement (location: source ID 22, line 212, chars 9034-9069, hits: 0) +- Branch (branch: 25, path: 0) (location: source ID 22, line 251, chars 10606-10690, hits: 0) +- Line (location: source ID 22, line 252, chars 10661-10683, hits: 0) +- Statement (location: source ID 22, line 252, chars 10661-10683, hits: 0) +- Branch (branch: 26, path: 0) (location: source ID 22, line 253, chars 10696-10772, hits: 0) +- Line (location: source ID 22, line 254, chars 10747-10765, hits: 0) +- Statement (location: source ID 22, line 254, chars 10747-10765, hits: 0) +- Branch (branch: 27, path: 0) (location: source ID 22, line 255, chars 10778-10862, hits: 0) +- Line (location: source ID 22, line 256, chars 10833-10855, hits: 0) +- Statement (location: source ID 22, line 256, chars 10833-10855, hits: 0) +- Branch (branch: 28, path: 1) (location: source ID 22, line 257, chars 10868-10950, hits: 0) +- Line (location: source ID 22, line 258, chars 10922-10943, hits: 0) +- Statement (location: source ID 22, line 258, chars 10922-10943, hits: 0) + +- Function "getSrcTotalFeeInUsdc" (location: source ID 22, line 265, chars 11048-11303, hits: 0) +- Line (location: source ID 22, line 266, chars 11178-11298, hits: 0) +- Statement (location: source ID 22, line 266, chars 11178-11298, hits: 0) +- Statement (location: source ID 22, line 266, chars 11185-11298, hits: 0) + +Uncovered for ../hardhat/contracts/Proxy/ChildPoolProxy.sol: + - Function "" (location: source ID 23, line 84, chars 5400-5657, hits: 0) + - Line (location: source ID 23, line 85, chars 5512-5533, hits: 0) + - Statement (location: source ID 23, line 85, chars 5512-5533, hits: 0) + - Line (location: source ID 23, line 87, chars 5613-5652, hits: 0) + - Statement (location: source ID 23, line 87, chars 5613-5652, hits: 0) + - Branch (branch: 0, path: 0) (location: source ID 23, line 101, chars 5985-6205, hits: 0) + - Branch (branch: 1, path: 0) (location: source ID 23, line 102, chars 6026-6147, hits: 0) + - Line (location: source ID 23, line 103, chars 6107-6138, hits: 0) + - Statement (location: source ID 23, line 103, chars 6107-6138, hits: 0) + - Line (location: source ID 23, line 105, chars 6163-6190, hits: 0) + - Statement (location: source ID 23, line 105, chars 6163-6190, hits: 0) + - Branch (branch: 2, path: 1) (location: source ID 23, line 108, chars 6219-6302, hits: 0) + - Statement (location: source ID 23, line 108, chars 6273-6302, hits: 0) + - Line (location: source ID 23, line 109, chars 6310-6327, hits: 0) + - Statement (location: source ID 23, line 109, chars 6310-6327, hits: 0) + +Uncovered for ../hardhat/contracts/Proxy/InfraProxy.sol: + - Function "" (location: source ID 24, line 84, chars 5369-5642, hits: 0) + - Line (location: source ID 24, line 89, chars 5497-5518, hits: 0) + - Statement (location: source ID 24, line 89, chars 5497-5518, hits: 0) + - Line (location: source ID 24, line 91, chars 5598-5637, hits: 0) + - Statement (location: source ID 24, line 91, chars 5598-5637, hits: 0) + - Branch (branch: 0, path: 0) (location: source ID 24, line 105, chars 5970-6190, hits: 0) + - Branch (branch: 1, path: 0) (location: source ID 24, line 106, chars 6011-6132, hits: 0) + - Line (location: source ID 24, line 107, chars 6092-6123, hits: 0) + - Statement (location: source ID 24, line 107, chars 6092-6123, hits: 0) + - Line (location: source ID 24, line 109, chars 6148-6175, hits: 0) + - Statement (location: source ID 24, line 109, chars 6148-6175, hits: 0) + - Line (location: source ID 24, line 113, chars 6295-6312, hits: 0) + - Statement (location: source ID 24, line 113, chars 6295-6312, hits: 0) + +Uncovered for ../hardhat/contracts/Proxy/ParentPoolProxy.sol: + - Function "" (location: source ID 25, line 84, chars 5404-5677, hits: 0) + - Line (location: source ID 25, line 89, chars 5532-5553, hits: 0) + - Statement (location: source ID 25, line 89, chars 5532-5553, hits: 0) + - Line (location: source ID 25, line 91, chars 5633-5672, hits: 0) + - Statement (location: source ID 25, line 91, chars 5633-5672, hits: 0) + - Branch (branch: 0, path: 0) (location: source ID 25, line 105, chars 6005-6225, hits: 0) + - Branch (branch: 1, path: 0) (location: source ID 25, line 106, chars 6046-6167, hits: 0) + - Line (location: source ID 25, line 107, chars 6127-6158, hits: 0) + - Statement (location: source ID 25, line 107, chars 6127-6158, hits: 0) + - Line (location: source ID 25, line 109, chars 6183-6210, hits: 0) + - Statement (location: source ID 25, line 109, chars 6183-6210, hits: 0) + - Branch (branch: 2, path: 1) (location: source ID 25, line 112, chars 6239-6322, hits: 0) + - Statement (location: source ID 25, line 112, chars 6293-6322, hits: 0) + - Line (location: source ID 25, line 113, chars 6330-6347, hits: 0) + - Statement (location: source ID 25, line 113, chars 6330-6347, hits: 0) \ No newline at end of file diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index f37f7b6dc..e9193d9f7 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -733,6 +733,9 @@ contract ProtocolMainnet is Test { assertEq(wEth.balanceOf(address(op)), amountIn / 1000); assertTrue(mUSDC.balanceOf(User) >= amountOutMin); vm.stopPrank(); + + vm.prank(defaultSender); + op.withdraw(defaultSender, address(wEth), amountIn / 1000); //=================================== Revert Leg =========================================\\ @@ -1492,6 +1495,9 @@ contract ProtocolMainnet is Test { assertEq(address(op).balance, 1*10**17 / 1000); assertTrue(mUSDC.balanceOf(address(User)) > USDC_INITIAL_BALANCE + amountOut); + vm.prank(defaultSender); + op.withdraw(defaultSender, address(0), amountIn / 1000); + ////================================ Empty Dex Data =================================\\\\\\ swapData[0] = IDexSwap.SwapData({ dexType: IDexSwap.DexType.UniswapV2Ether, diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index 05ed38662..b86ca4acb 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -597,12 +597,48 @@ contract ProtocolTestnet is Test { dexData: abi.encode(mockBase, path, to, deadline) }); - vm.startPrank(User); tUSDC.approve(address(op), USDC_INITIAL_BALANCE + 1); vm.expectRevert(abi.encodeWithSelector(Orchestrator_InvalidAmount.selector)); op.bridge(data, swapData); vm.stopPrank(); + + ///==================== Ether Check + + + //===== Mock the value. + //In this case, the value is passed as a param through the function + //Also is transferred in the call + amountIn = 1*10**17; + + //===== Mock the data for payload to send to the function + uint256 amountOut = 350*10*6; + + path[0] = address(wEth); + path[1] = address(mUSDC); + to = address(User); + deadline = block.timestamp + 1800; + + //===== Gives User some ether and checks the balance + vm.deal(User, 1*10**17); + assertEq(User.balance, 1*10**17); + + //===== Mock the payload to send on the function + swapData[0] = IDexSwap.SwapData({ + dexType: IDexSwap.DexType.UniswapV2Ether, + fromToken: address(0), + fromAmount: 1*10**16, + toToken: address(mUSDC), + toAmount: amountOut, + toAmountMin: amountOut, + dexData: abi.encode(mockBase, path, deadline) + }); + + //===== Start transaction calling the function and passing the payload + vm.startPrank(User); + vm.expectRevert(abi.encodeWithSelector(Orchestrator_InvalidAmount.selector)); + op.swap{value: amountIn}(swapData, User); + vm.stopPrank(); } error Orchestrator_InvalidBridgeData(); @@ -992,7 +1028,7 @@ contract ProtocolTestnet is Test { //////////////////////////////////////////////////////////////////////////////////// error Concero_ItsNotOrchestrator(address); - function test_swapAndBridgeWithoutFunctions() public setters{ + function test_swapAndBridgeTestnet() public setters{ helper(); /////////////////////////// SWAP DATA MOCKED \\\\\\\\\\\\\\\\\\\\\\\\\\\\ diff --git a/packages/hardhat/contracts/ConceroChildPool.sol b/packages/hardhat/contracts/ConceroChildPool.sol index e5e0736aa..3c84c4431 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -161,14 +161,14 @@ contract ConceroChildPool is CCIPReceiver, ChildPoolStorage { * @dev If Orchestrator took a loan and the money didn't rebalance yet, it will be left behind. */ function liquidatePool() external isProxy onlyMessenger { - uint256 numberOfPools = s_poolsToDistribute.length; + uint256 numberOfPools = s_poolChainSelectors.length; if (numberOfPools < ALLOWED) revert ConceroChildPool_ThereIsNoPoolToDistribute(); uint256 amountToSentToEachPool = (i_USDC.balanceOf(address(this)) / numberOfPools) - 1; for (uint256 i; i < numberOfPools; ) { //This is a function to deal with adding&removing pools. So, the second param will always be address(0) - _ccipSend(s_poolsToDistribute[i], address(0), amountToSentToEachPool); + _ccipSend(s_poolChainSelectors[i], address(0), amountToSentToEachPool); unchecked { ++i; } @@ -224,7 +224,7 @@ contract ConceroChildPool is CCIPReceiver, ChildPoolStorage { function setPools(uint64 _chainSelector, address _pool) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroChildPool_InvalidAddress(); - s_poolsToDistribute.push(_chainSelector); + s_poolChainSelectors.push(_chainSelector); s_poolToSendTo[_chainSelector] = _pool; emit ConceroChildPool_PoolReceiverUpdated(_chainSelector, _pool); @@ -236,10 +236,10 @@ contract ConceroChildPool is CCIPReceiver, ChildPoolStorage { */ function removePools(uint64 _chainSelector) external payable isProxy onlyOwner { - for (uint256 i; i < s_poolsToDistribute.length; ) { - if (s_poolsToDistribute[i] == _chainSelector) { - s_poolsToDistribute[i] = s_poolsToDistribute[s_poolsToDistribute.length - 1]; - s_poolsToDistribute.pop(); + for (uint256 i; i < s_poolChainSelectors.length; ) { + if (s_poolChainSelectors[i] == _chainSelector) { + s_poolChainSelectors[i] = s_poolChainSelectors[s_poolChainSelectors.length - 1]; + s_poolChainSelectors.pop(); delete s_poolToSendTo[_chainSelector]; } unchecked { @@ -292,7 +292,7 @@ contract ConceroChildPool is CCIPReceiver, ChildPoolStorage { * @param _liquidityProviderAddress The liquidity provider that requested Withdraw. If it's a rebalance, it will be address(0) * @param _amount amount of the token to be sent * @dev This function will sent the address of the user as data. This address will be used to update the mapping on ParentPool. - * @dev when processing withdrawals, the _chainSelector will always be the index 0 of s_poolsToDistribute + * @dev when processing withdrawals, the _chainSelector will always be the index 0 of s_poolChainSelectors */ function _ccipSend(uint64 _chainSelector, address _liquidityProviderAddress, uint256 _amount) internal onlyMessenger isProxy returns (bytes32 messageId) { if (_amount > i_USDC.balanceOf(address(this))) revert ConceroChildPool_InsufficientBalance(); diff --git a/packages/hardhat/contracts/ConceroParentPool.sol b/packages/hardhat/contracts/ConceroParentPool.sol index b2df12e1f..a34bc07c7 100644 --- a/packages/hardhat/contracts/ConceroParentPool.sol +++ b/packages/hardhat/contracts/ConceroParentPool.sol @@ -227,7 +227,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { if (_usdcAmount < MIN_DEPOSIT) revert ConceroParentPool_AmountBelowMinimum(MIN_DEPOSIT); if (s_maxDeposit != 0 && s_maxDeposit < _usdcAmount + i_USDC.balanceOf(address(this)) + s_loansInUse) revert ConceroParentPool_MaxCapReached(s_maxDeposit); - uint256 numberOfPools = s_poolsToDistribute.length; + uint256 numberOfPools = s_poolChainSelectors.length; if (numberOfPools < ALLOWED) revert ConceroParentPool_ThereIsNoPoolToDistribute(); @@ -376,7 +376,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { function setPools(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroParentPool_InvalidAddress(); - s_poolsToDistribute.push(_chainSelector); + s_poolChainSelectors.push(_chainSelector); s_poolToSendTo[_chainSelector] = _pool; emit ConceroParentPool_PoolReceiverUpdated(_chainSelector, _pool); @@ -392,7 +392,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { args[0] = abi.encodePacked(s_hashSum); args[1] = abi.encodePacked(s_ethersHashSum); args[2] = abi.encodePacked(_chainSelector); - args[3] = abi.encodePacked(s_poolsToDistribute.length + 1); + args[3] = abi.encodePacked(s_poolChainSelectors.length + 1); //todo: @nikita pools have to track requests in order to prevent 4 nodes triggering a rebalance on the same pool bytes32 requestId /* = _sendRequest(args, REBALANCE_JS_CODE)*/; @@ -410,11 +410,11 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { */ function removePools(uint64 _chainSelector) external payable isProxy onlyOwner { address removedPool; - for (uint256 i; i < s_poolsToDistribute.length; ) { - if (s_poolsToDistribute[i] == _chainSelector) { + for (uint256 i; i < s_poolChainSelectors.length; ) { + if (s_poolChainSelectors[i] == _chainSelector) { removedPool = s_poolToSendTo[_chainSelector]; - s_poolsToDistribute[i] = s_poolsToDistribute[s_poolsToDistribute.length - 1]; - s_poolsToDistribute.pop(); + s_poolChainSelectors[i] = s_poolChainSelectors[s_poolChainSelectors.length - 1]; + s_poolChainSelectors.pop(); delete s_poolToSendTo[_chainSelector]; } unchecked { @@ -495,9 +495,9 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { * @param _amountToDistribute amount of USDC should be distributed to the pools. */ function _distributeLiquidity(uint256 _amountToDistribute) internal { - uint256 numberOfPools = s_poolsToDistribute.length; + uint256 numberOfPools = s_poolChainSelectors.length; for (uint256 i; i < numberOfPools; ) { - _ccipSend(s_poolsToDistribute[i], _amountToDistribute); + _ccipSend(s_poolChainSelectors[i], _amountToDistribute); unchecked { ++i; @@ -620,7 +620,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { * @dev _totalUSDCCrossChain MUST have 10**6 decimals. */ function _updateUsdcAmountEarned(address _liquidityProvider, uint256 _lpSupplyBeforeRequest, uint256 _lpToBurn, uint256 _totalUSDCCrossChain) private { - uint256 numberOfPools = s_poolsToDistribute.length; + uint256 numberOfPools = s_poolChainSelectors.length; uint256 totalCrossChainBalance = _totalUSDCCrossChain + i_USDC.balanceOf(address(this)) + s_loansInUse; //USDC_WITHDRAWABLE = POOL_BALANCE x (LP_INPUT_AMOUNT / TOTAL_LP) @@ -647,7 +647,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { } // function _calculateDepositTransactionFee(uint256 _amountToDistribute) internal view returns(uint256 _totalUSDCCost){ - // uint256 numberOfPools = s_poolsToDistribute.length; + // uint256 numberOfPools = s_poolChainSelectors.length; // uint256 costOfLinkForLiquidityDistribution; // uint256 premiumFee = Orchestrator(i_infraProxy).clfPremiumFees(BASE_CHAIN_SELECTOR); // uint256 lastNativeUSDCRate = Orchestrator(i_infraProxy).s_latestNativeUsdcRate(); @@ -655,10 +655,10 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { // uint256 lastBaseGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); // for(uint256 i; i < numberOfPools; ){ - // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), s_poolToSendTo[s_poolsToDistribute[i]]); + // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), s_poolToSendTo[s_poolChainSelectors[i]]); // //Link cost for all transactions - // costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(s_poolsToDistribute[i], evm2AnyMessage); + // costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(s_poolChainSelectors[i], evm2AnyMessage); // unchecked { // ++i; // } @@ -672,7 +672,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { // } // function _calculateWithdrawTransactionsFee(uint256 _amountToReceive) internal view returns(uint256 _totalUSDCCost){ - // uint256 numberOfPools = s_poolsToDistribute.length; + // uint256 numberOfPools = s_poolChainSelectors.length; // uint256 premiumFee = Orchestrator(i_infraProxy).clfPremiumFees(BASE_CHAIN_SELECTOR); // uint256 baseLastGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); // uint256 lastNativeUSDCRate = Orchestrator(i_infraProxy).s_latestNativeUsdcRate(); @@ -687,7 +687,7 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { // //Link cost for all transactions // costOfLinkForLiquidityWithdraw += IRouterClient(i_ccipRouter).getFee(BASE_CHAIN_SELECTOR, evm2AnyMessage); //here the chainSelector must be Base's? // //USDC costs for all writing from the above transactions - // costOfCCIPSendToPoolExecution += Orchestrator(i_infraProxy).s_lastGasPrices(s_poolsToDistribute[i]) * WRITE_FUNCTIONS_COST; + // costOfCCIPSendToPoolExecution += Orchestrator(i_infraProxy).s_lastGasPrices(s_poolChainSelectors[i]) * WRITE_FUNCTIONS_COST; // unchecked { // ++i; // } diff --git a/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol b/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol index aff58716c..c4f8dcec6 100644 --- a/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol @@ -30,7 +30,7 @@ contract ParentPoolStorage { ///STORAGE/// ///////////// ///@notice array of Pools to receive Liquidity through `ccipSend` function - uint64[] s_poolsToDistribute; + uint64[] s_poolChainSelectors; ///@notice Mapping to keep track of valid pools to transfer in case of liquidation or rebalance mapping(uint64 chainSelector => address pool) public s_poolToSendTo; diff --git a/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts b/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts index 3697f3ab2..f4d733ed8 100644 --- a/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts +++ b/packages/hardhat/tasks/concero/deployPool/setChildProxyVariables.ts @@ -74,6 +74,54 @@ async function setConceroProxySender(hre) { } } +async function addPoolsToAllChains(hre) { + const chain = chains[hre.network.name]; + const { name: chainName, viemChain, url } = chain; + const clients = getClients(viemChain, url); + const { publicClient, account, walletClient } = clients; + const { abi } = await load("../artifacts/contracts/ConceroChildPool.sol/ConceroChildPool.json"); + if (!chainName) throw new Error("Chain name not found"); + + for (const dstChain of liveChains) { + try { + const { name: dstChainName, chainSelector: dstChainSelector } = dstChain; + if (!dstChainName) throw new Error("Destination chain name not found"); + if (!dstChainSelector) throw new Error("Destination chain selector not found"); + + const poolAddressToAdd = + dstChain.chainId === CNetworks.base.chainId || dstChain.chainId === CNetworks.baseSepolia.chainId + ? (getEnvVar(`PARENT_POOL_PROXY_${networkEnvKeys[dstChain.name]}` as keyof env) as Address) + : (getEnvVar(`CHILD_POOL_PROXY_${networkEnvKeys[dstChain.name]}` as keyof env) as Address); + const conceroPoolAddress = getEnvVar(`CHILD_POOL_PROXY_${networkEnvKeys[chainName]}` as keyof env) as Address; + + const { request: setPoolReq } = await publicClient.simulateContract({ + address: conceroPoolAddress, + functionName: "setPools", + args: [dstChainSelector, poolAddressToAdd], + abi, + account, + viemChain, + }); + const setPoolHash = await walletClient.writeContract(setPoolReq); + + const { cumulativeGasUsed: setPoolGasUsed } = await publicClient.waitForTransactionReceipt({ + hash: setPoolHash, + }); + + log( + `Added pool ${poolAddressToAdd} for chain ${dstChain.name}. Gas used: ${setPoolGasUsed.toString()}`, + "addPoolsToAllChains", + ); + } catch (error) { + log( + `Error adding pool for chain ${dstChain.name}. Pool address: ${poolAddressToAdd}`, + "addPoolsToAllChains", + ); + } + } +} + export async function setChildProxyVariables(hre) { await setConceroProxySender(hre); + await addPoolsToAllChains(hre); } From 04f1ab263ff3cc348332ceaea97ebdbc35203b86 Mon Sep 17 00:00:00 2001 From: Barba Date: Mon, 15 Jul 2024 12:35:10 -0300 Subject: [PATCH 12/17] Update Test Suit --- packages/foundry/coverageTwo.txt | 240 +----------------- .../MainnetFork/ProtocolMainnet.t.sol | 6 +- .../TestnetFork/ProtocolTestnet.t.sol | 76 +++++- .../UnitTests/ParentPool.t.sol | 19 +- .../contracts/Libraries/ChildPoolStorage.sol | 2 +- 5 files changed, 102 insertions(+), 241 deletions(-) diff --git a/packages/foundry/coverageTwo.txt b/packages/foundry/coverageTwo.txt index 266625301..c2a121067 100644 --- a/packages/foundry/coverageTwo.txt +++ b/packages/foundry/coverageTwo.txt @@ -191,190 +191,6 @@ Uncovered for ../hardhat/contracts/ConceroChildPool.sol: - Statement (location: source ID 3, line 323, chars 14601-14681, hits: 0) Uncovered for ../hardhat/contracts/ConceroParentPool.sol: -- Function "onlyAllowlistedSenderAndChainSelector" (location: source ID 6, line 146, chars 8902-9123, hits: 0) -- Line (location: source ID 6, line 147, chars 8999-9059, hits: 0) -- Statement (location: source ID 6, line 147, chars 8999-9059, hits: 0) -- Branch (branch: 0, path: 0) (location: source ID 6, line 147, chars 8995-9111, hits: 0) -- Branch (branch: 0, path: 1) (location: source ID 6, line 147, chars 8995-9111, hits: 0) -- Statement (location: source ID 6, line 147, chars 9061-9111, hits: 0) -- Branch (branch: 1, path: 1) (location: source ID 6, line 155, chars 9252-9347, hits: 0) -- Branch (branch: 2, path: 1) (location: source ID 6, line 160, chars 9390-9460, hits: 0) -- Branch (branch: 3, path: 1) (location: source ID 6, line 168, chars 9593-9680, hits: 0) -- Statement (location: source ID 6, line 168, chars 9631-9680, hits: 0) -- Function "" (location: source ID 6, line 177, chars 9969-10617, hits: 0) -- Line (location: source ID 6, line 190, chars 10312-10328, hits: 0) -- Statement (location: source ID 6, line 190, chars 10312-10328, hits: 0) -- Line (location: source ID 6, line 191, chars 10334-10368, hits: 0) -- Statement (location: source ID 6, line 191, chars 10334-10368, hits: 0) -- Line (location: source ID 6, line 192, chars 10374-10402, hits: 0) -- Statement (location: source ID 6, line 192, chars 10374-10402, hits: 0) -- Line (location: source ID 6, line 193, chars 10408-10447, hits: 0) -- Statement (location: source ID 6, line 193, chars 10408-10447, hits: 0) -- Line (location: source ID 6, line 194, chars 10453-10475, hits: 0) -- Statement (location: source ID 6, line 194, chars 10453-10475, hits: 0) -- Line (location: source ID 6, line 195, chars 10481-10505, hits: 0) -- Statement (location: source ID 6, line 195, chars 10481-10505, hits: 0) -- Line (location: source ID 6, line 196, chars 10511-10556, hits: 0) -- Statement (location: source ID 6, line 196, chars 10511-10556, hits: 0) -- Line (location: source ID 6, line 197, chars 10562-10590, hits: 0) -- Statement (location: source ID 6, line 197, chars 10562-10590, hits: 0) -- Line (location: source ID 6, line 198, chars 10596-10612, hits: 0) -- Statement (location: source ID 6, line 198, chars 10596-10612, hits: 0) -- Branch (branch: 6, path: 1) (location: source ID 6, line 215, chars 11370-11494, hits: 0) -- Line (location: source ID 6, line 217, chars 11501-11538, hits: 0) -- Statement (location: source ID 6, line 217, chars 11501-11538, hits: 0) -- Line (location: source ID 6, line 219, chars 11545-11592, hits: 0) -- Statement (location: source ID 6, line 219, chars 11545-11592, hits: 0) -- Branch (branch: 8, path: 1) (location: source ID 6, line 228, chars 11897-12051, hits: 0) -- Branch (branch: 10, path: 1) (location: source ID 6, line 265, chars 13506-13596, hits: 0) -- Branch (branch: 11, path: 1) (location: source ID 6, line 266, chars 13602-13717, hits: 0) -- Statement (location: source ID 6, line 266, chars 13662-13717, hits: 0) -- Function "completeWithdrawal" (location: source ID 6, line 291, chars 14547-15637, hits: 0) -- Line (location: source ID 6, line 292, chars 14600-14678, hits: 0) -- Statement (location: source ID 6, line 292, chars 14600-14678, hits: 0) -- Line (location: source ID 6, line 294, chars 14689-14717, hits: 0) -- Statement (location: source ID 6, line 294, chars 14689-14717, hits: 0) -- Branch (branch: 12, path: 0) (location: source ID 6, line 294, chars 14685-14791, hits: 0) -- Branch (branch: 12, path: 1) (location: source ID 6, line 294, chars 14685-14791, hits: 0) -- Statement (location: source ID 6, line 294, chars 14719-14791, hits: 0) -- Line (location: source ID 6, line 295, chars 14801-14856, hits: 0) -- Statement (location: source ID 6, line 295, chars 14801-14856, hits: 0) -- Statement (location: source ID 6, line 295, chars 14825-14856, hits: 0) -- Branch (branch: 13, path: 0) (location: source ID 6, line 295, chars 14797-14904, hits: 0) -- Branch (branch: 13, path: 1) (location: source ID 6, line 295, chars 14797-14904, hits: 0) -- Statement (location: source ID 6, line 295, chars 14858-14904, hits: 0) -- Line (location: source ID 6, line 297, chars 14911-15023, hits: 0) -- Statement (location: source ID 6, line 297, chars 14911-15023, hits: 0) -- Line (location: source ID 6, line 299, chars 15030-15074, hits: 0) -- Statement (location: source ID 6, line 299, chars 15030-15074, hits: 0) -- Line (location: source ID 6, line 304, chars 15278-15362, hits: 0) -- Statement (location: source ID 6, line 304, chars 15278-15362, hits: 0) -- Line (location: source ID 6, line 306, chars 15369-15448, hits: 0) -- Statement (location: source ID 6, line 306, chars 15369-15448, hits: 0) -- Line (location: source ID 6, line 307, chars 15454-15486, hits: 0) -- Statement (location: source ID 6, line 307, chars 15454-15486, hits: 0) -- Line (location: source ID 6, line 310, chars 15578-15632, hits: 0) -- Statement (location: source ID 6, line 310, chars 15578-15632, hits: 0) -- Branch (branch: 14, path: 0) (location: source ID 6, line 319, chars 15976-16067, hits: 0) -- Line (location: source ID 6, line 320, chars 16073-16113, hits: 0) -- Statement (location: source ID 6, line 320, chars 16073-16113, hits: 0) -- Function "_ccipReceive" (location: source ID 6, line 453, chars 21125-23075, hits: 0) -- Line (location: source ID 6, line 459, chars 21479-21606, hits: 0) -- Statement (location: source ID 6, line 459, chars 21479-21606, hits: 0) -- Statement (location: source ID 6, line 459, chars 21546-21606, hits: 0) -- Line (location: source ID 6, line 461, chars 21613-21696, hits: 0) -- Statement (location: source ID 6, line 461, chars 21613-21696, hits: 0) -- Line (location: source ID 6, line 463, chars 21707-21722, hits: 0) -- Statement (location: source ID 6, line 463, chars 21707-21722, hits: 0) -- Branch (branch: 19, path: 0) (location: source ID 6, line 463, chars 21703-22320, hits: 0) -- Branch (branch: 19, path: 1) (location: source ID 6, line 463, chars 21703-22320, hits: 0) -- Line (location: source ID 6, line 464, chars 21732-21847, hits: 0) -- Statement (location: source ID 6, line 464, chars 21732-21847, hits: 0) -- Statement (location: source ID 6, line 464, chars 21774-21847, hits: 0) -- Line (location: source ID 6, line 466, chars 21860-21985, hits: 0) -- Statement (location: source ID 6, line 466, chars 21860-21985, hits: 0) -- Statement (location: source ID 6, line 466, chars 21955-21985, hits: 0) -- Branch (branch: 20, path: 0) (location: source ID 6, line 466, chars 21856-22182, hits: 0) -- Branch (branch: 20, path: 1) (location: source ID 6, line 466, chars 21856-22182, hits: 0) -- Line (location: source ID 6, line 467, chars 21997-22040, hits: 0) -- Statement (location: source ID 6, line 467, chars 21997-22040, hits: 0) -- Line (location: source ID 6, line 471, chars 22260-22305, hits: 0) -- Statement (location: source ID 6, line 471, chars 22260-22305, hits: 0) -- Line (location: source ID 6, line 473, chars 22330-22362, hits: 0) -- Statement (location: source ID 6, line 473, chars 22330-22362, hits: 0) -- Statement (location: source ID 6, line 473, chars 22352-22362, hits: 0) -- Branch (branch: 21, path: 0) (location: source ID 6, line 473, chars 22326-22800, hits: 0) -- Branch (branch: 21, path: 1) (location: source ID 6, line 473, chars 22326-22800, hits: 0) -- Line (location: source ID 6, line 474, chars 22372-22458, hits: 0) -- Statement (location: source ID 6, line 474, chars 22372-22458, hits: 0) -- Line (location: source ID 6, line 477, chars 22517-22701, hits: 0) -- Statement (location: source ID 6, line 477, chars 22517-22701, hits: 0) -- Line (location: source ID 6, line 481, chars 22710-22793, hits: 0) -- Statement (location: source ID 6, line 481, chars 22710-22793, hits: 0) -- Line (location: source ID 6, line 484, chars 22806-23070, hits: 0) -- Statement (location: source ID 6, line 484, chars 22806-23070, hits: 0) -- Branch (branch: 22, path: 1) (location: source ID 6, line 517, chars 24020-24158, hits: 0) -- Statement (location: source ID 6, line 517, chars 24069-24158, hits: 0) -- Function "fulfillRequest" (location: source ID 6, line 562, chars 26115-26931, hits: 0) -- Line (location: source ID 6, line 563, chars 26223-26279, hits: 0) -- Statement (location: source ID 6, line 563, chars 26223-26279, hits: 0) -- Line (location: source ID 6, line 565, chars 26290-26304, hits: 0) -- Statement (location: source ID 6, line 565, chars 26290-26304, hits: 0) -- Branch (branch: 23, path: 0) (location: source ID 6, line 565, chars 26286-26393, hits: 0) -- Branch (branch: 23, path: 1) (location: source ID 6, line 565, chars 26286-26393, hits: 0) -- Line (location: source ID 6, line 566, chars 26314-26372, hits: 0) -- Statement (location: source ID 6, line 566, chars 26314-26372, hits: 0) -- Line (location: source ID 6, line 567, chars 26380-26387, hits: 0) -- Statement (location: source ID 6, line 567, chars 26380-26387, hits: 0) -- Line (location: source ID 6, line 570, chars 26399-26458, hits: 0) -- Statement (location: source ID 6, line 570, chars 26399-26458, hits: 0) -- Statement (location: source ID 6, line 570, chars 26427-26458, hits: 0) -- Line (location: source ID 6, line 571, chars 26464-26531, hits: 0) -- Statement (location: source ID 6, line 571, chars 26464-26531, hits: 0) -- Statement (location: source ID 6, line 571, chars 26486-26531, hits: 0) -- Line (location: source ID 6, line 573, chars 26542-26595, hits: 0) -- Statement (location: source ID 6, line 573, chars 26542-26595, hits: 0) -- Branch (branch: 24, path: 0) (location: source ID 6, line 573, chars 26538-26732, hits: 0) -- Branch (branch: 24, path: 1) (location: source ID 6, line 573, chars 26538-26732, hits: 0) -- Line (location: source ID 6, line 574, chars 26605-26725, hits: 0) -- Statement (location: source ID 6, line 574, chars 26605-26725, hits: 0) -- Line (location: source ID 6, line 575, chars 26742-26800, hits: 0) -- Statement (location: source ID 6, line 575, chars 26742-26800, hits: 0) -- Branch (branch: 25, path: 0) (location: source ID 6, line 575, chars 26738-26927, hits: 0) -- Branch (branch: 25, path: 1) (location: source ID 6, line 575, chars 26738-26927, hits: 0) -- Line (location: source ID 6, line 576, chars 26810-26920, hits: 0) -- Statement (location: source ID 6, line 576, chars 26810-26920, hits: 0) -- Function "_updateDepositInfoAndMintLPTokens" (location: source ID 6, line 592, chars 27521-28399, hits: 0) -- Line (location: source ID 6, line 600, chars 27783-27867, hits: 0) -- Statement (location: source ID 6, line 600, chars 27783-27867, hits: 0) -- Statement (location: source ID 6, line 600, chars 27820-27867, hits: 0) -- Line (location: source ID 6, line 601, chars 27873-27949, hits: 0) -- Statement (location: source ID 6, line 601, chars 27873-27949, hits: 0) -- Statement (location: source ID 6, line 601, chars 27908-27949, hits: 0) -- Line (location: source ID 6, line 605, chars 28105-28342, hits: 0) -- Statement (location: source ID 6, line 605, chars 28105-28342, hits: 0) -- Statement (location: source ID 6, line 605, chars 28130-28342, hits: 0) -- Line (location: source ID 6, line 609, chars 28349-28394, hits: 0) -- Statement (location: source ID 6, line 609, chars 28349-28394, hits: 0) -- Function "_updateUsdcAmountEarned" (location: source ID 6, line 622, chars 28962-30428, hits: 0) -- Line (location: source ID 6, line 623, chars 29118-29169, hits: 0) -- Statement (location: source ID 6, line 623, chars 29118-29169, hits: 0) -- Line (location: source ID 6, line 624, chars 29175-29277, hits: 0) -- Statement (location: source ID 6, line 624, chars 29175-29277, hits: 0) -- Statement (location: source ID 6, line 624, chars 29208-29277, hits: 0) -- Statement (location: source ID 6, line 624, chars 29208-29262, hits: 0) -- Statement (location: source ID 6, line 624, chars 29231-29262, hits: 0) -- Line (location: source ID 6, line 627, chars 29354-29519, hits: 0) -- Statement (location: source ID 6, line 627, chars 29354-29519, hits: 0) -- Statement (location: source ID 6, line 627, chars 29381-29519, hits: 0) -- Line (location: source ID 6, line 630, chars 29526-29614, hits: 0) -- Statement (location: source ID 6, line 630, chars 29526-29614, hits: 0) -- Statement (location: source ID 6, line 630, chars 29569-29614, hits: 0) -- Line (location: source ID 6, line 632, chars 29621-30135, hits: 0) -- Statement (location: source ID 6, line 632, chars 29621-30135, hits: 0) -- Statement (location: source ID 6, line 632, chars 29661-30135, hits: 0) -- Line (location: source ID 6, line 641, chars 30142-30238, hits: 0) -- Statement (location: source ID 6, line 641, chars 30142-30238, hits: 0) -- Line (location: source ID 6, line 643, chars 30245-30300, hits: 0) -- Statement (location: source ID 6, line 643, chars 30245-30300, hits: 0) -- Line (location: source ID 6, line 644, chars 30306-30359, hits: 0) -- Statement (location: source ID 6, line 644, chars 30306-30359, hits: 0) -- Line (location: source ID 6, line 646, chars 30366-30423, hits: 0) -- Statement (location: source ID 6, line 646, chars 30366-30423, hits: 0) -- Function "_convertToLPTokenDecimals" (location: source ID 6, line 723, chars 34272-34454, hits: 0) -- Line (location: source ID 6, line 724, chars 34382-34449, hits: 0) -- Statement (location: source ID 6, line 724, chars 34382-34449, hits: 0) -- Function "_convertToUSDCTokenDecimals" (location: source ID 6, line 732, chars 34629-34809, hits: 0) -- Line (location: source ID 6, line 733, chars 34739-34804, hits: 0) -- Statement (location: source ID 6, line 733, chars 34739-34804, hits: 0) -- Function "getMaxCap" (location: source ID 6, line 740, chars 34997-35091, hits: 0) -- Line (location: source ID 6, line 741, chars 35064-35086, hits: 0) -- Statement (location: source ID 6, line 741, chars 35064-35086, hits: 0) -- Function "getUsdcInUse" (location: source ID 6, line 744, chars 35095-35198, hits: 0) -- Line (location: source ID 6, line 745, chars 35168-35193, hits: 0) -- Statement (location: source ID 6, line 745, chars 35168-35193, hits: 0) -- Line (location: source ID 6, line 767, chars 35869-35881, hits: 0) -- Statement (location: source ID 6, line 767, chars 35869-35881, hits: 0) Uncovered for ../hardhat/contracts/DexSwap.sol: - Function "" (location: source ID 8, line 53, chars 2304-2394, hits: 0) @@ -425,50 +241,18 @@ Uncovered for ../hardhat/contracts/LPToken.sol: - Statement (location: source ID 16, line 19, chars 873-890, hits: 0) Uncovered for ../hardhat/contracts/Orchestrator.sol: -- Function "addUnconfirmedTX" (location: source ID 22, line 167, chars 7177-7743, hits: 0) -- Line (location: source ID 22, line 177, chars 7433-7656, hits: 0) -- Statement (location: source ID 22, line 177, chars 7433-7656, hits: 0) -- Statement (location: source ID 22, line 177, chars 7469-7656, hits: 0) -- Line (location: source ID 22, line 180, chars 7666-7682, hits: 0) -- Statement (location: source ID 22, line 180, chars 7666-7682, hits: 0) -- Branch (branch: 15, path: 0) (location: source ID 22, line 180, chars 7662-7738, hits: 0) -- Branch (branch: 15, path: 1) (location: source ID 22, line 180, chars 7662-7738, hits: 0) -- Statement (location: source ID 22, line 180, chars 7684-7738, hits: 0) -- Branch (branch: 17, path: 0) (location: source ID 22, line 192, chars 8142-8228, hits: 0) -- Line (location: source ID 22, line 194, chars 8235-8280, hits: 0) -- Statement (location: source ID 22, line 194, chars 8235-8280, hits: 0) - -- Function "getSrcTotalFeeInUsdcViaDelegateCall" (location: source ID 22, line 197, chars 8289-8753, hits: 0) -- Line (location: source ID 22, line 198, chars 8429-8600, hits: 0) -- Statement (location: source ID 22, line 198, chars 8429-8600, hits: 0) -- Statement (location: source ID 22, line 198, chars 8465-8600, hits: 0) -- Line (location: source ID 22, line 202, chars 8611-8627, hits: 0) -- Statement (location: source ID 22, line 202, chars 8611-8627, hits: 0) -- Branch (branch: 18, path: 0) (location: source ID 22, line 202, chars 8607-8683, hits: 0) -- Branch (branch: 18, path: 1) (location: source ID 22, line 202, chars 8607-8683, hits: 0) -- Statement (location: source ID 22, line 202, chars 8629-8683, hits: 0) -- Line (location: source ID 22, line 204, chars 8690-8748, hits: 0) -- Statement (location: source ID 22, line 204, chars 8690-8748, hits: 0) -- Statement (location: source ID 22, line 204, chars 8697-8748, hits: 0) -- Branch (branch: 19, path: 1) (location: source ID 22, line 212, chars 9012-9069, hits: 0) -- Statement (location: source ID 22, line 212, chars 9034-9069, hits: 0) -- Branch (branch: 25, path: 0) (location: source ID 22, line 251, chars 10606-10690, hits: 0) -- Line (location: source ID 22, line 252, chars 10661-10683, hits: 0) -- Statement (location: source ID 22, line 252, chars 10661-10683, hits: 0) -- Branch (branch: 26, path: 0) (location: source ID 22, line 253, chars 10696-10772, hits: 0) -- Line (location: source ID 22, line 254, chars 10747-10765, hits: 0) -- Statement (location: source ID 22, line 254, chars 10747-10765, hits: 0) -- Branch (branch: 27, path: 0) (location: source ID 22, line 255, chars 10778-10862, hits: 0) -- Line (location: source ID 22, line 256, chars 10833-10855, hits: 0) -- Statement (location: source ID 22, line 256, chars 10833-10855, hits: 0) -- Branch (branch: 28, path: 1) (location: source ID 22, line 257, chars 10868-10950, hits: 0) -- Line (location: source ID 22, line 258, chars 10922-10943, hits: 0) -- Statement (location: source ID 22, line 258, chars 10922-10943, hits: 0) - -- Function "getSrcTotalFeeInUsdc" (location: source ID 22, line 265, chars 11048-11303, hits: 0) -- Line (location: source ID 22, line 266, chars 11178-11298, hits: 0) -- Statement (location: source ID 22, line 266, chars 11178-11298, hits: 0) -- Statement (location: source ID 22, line 266, chars 11185-11298, hits: 0) + - Branch (branch: 25, path: 0) (location: source ID 22, line 251, chars 10606-10690, hits: 0) + - Line (location: source ID 22, line 252, chars 10661-10683, hits: 0) + - Statement (location: source ID 22, line 252, chars 10661-10683, hits: 0) + - Branch (branch: 26, path: 0) (location: source ID 22, line 253, chars 10696-10772, hits: 0) + - Line (location: source ID 22, line 254, chars 10747-10765, hits: 0) + - Statement (location: source ID 22, line 254, chars 10747-10765, hits: 0) + - Branch (branch: 27, path: 0) (location: source ID 22, line 255, chars 10778-10862, hits: 0) + - Line (location: source ID 22, line 256, chars 10833-10855, hits: 0) + - Statement (location: source ID 22, line 256, chars 10833-10855, hits: 0) + - Branch (branch: 28, path: 1) (location: source ID 22, line 257, chars 10868-10950, hits: 0) + - Line (location: source ID 22, line 258, chars 10922-10943, hits: 0) + - Statement (location: source ID 22, line 258, chars 10922-10943, hits: 0) Uncovered for ../hardhat/contracts/Proxy/ChildPoolProxy.sol: - Function "" (location: source ID 23, line 84, chars 5400-5657, hits: 0) diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index e9193d9f7..dd4f60ca4 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -118,7 +118,6 @@ contract ProtocolMainnet is Test { ConceroParentPool wMaster; ConceroChildPool wChild; - //==== Create the instance to forked tokens IWETH wEth; IWETH arbWEth; @@ -167,6 +166,7 @@ contract ProtocolMainnet is Test { address Messenger = 0x11111003F38DfB073C6FeE2F5B35A0e57dAc4715; address LP = makeAddr("LiquidityProvider"); address defaultSender = 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38; + address baseSubOwner = 0xddDd5f804B9D293dce8819d232e8D76381605a62; address subOwner = 0xDddDDb8a8E41C194ac6542a0Ad7bA663A72741E0; uint256 baseMainFork; @@ -500,7 +500,7 @@ contract ProtocolMainnet is Test { assertEq(op.s_conceroContracts(arbChainSelector), address(opDst)); vm.stopPrank(); - vm.startPrank(address(subOwner)); + vm.startPrank(baseSubOwner); functionsRouterBase.addConsumer(14, address(op)); functionsRouterBase.addConsumer(14, address(wMaster)); functionsRouterBase.addConsumer(14, address(automation)); @@ -528,7 +528,7 @@ contract ProtocolMainnet is Test { assertEq(opDst.s_poolReceiver(baseChainSelector), address(wMaster)); vm.stopPrank(); - vm.startPrank(address(subOwner)); + vm.startPrank(address(baseSubOwner)); functionsRouterArb.addConsumer(22, address(opDst)); functionsRouterArb.addConsumer(22, address(wChild)); vm.stopPrank(); diff --git a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol index b86ca4acb..9306a0485 100644 --- a/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/TestnetFork/ProtocolTestnet.t.sol @@ -146,6 +146,8 @@ contract ProtocolTestnet is Test { address ccipBnM = 0x88A2d74F47a237a62e7A51cdDa67270CE381555e; address ccipBnMArb = 0xA8C0c11bf64AF62CDCA6f93D3769B88BdD7cb93D; address registryAddress = 0x8B1565DbAF0577F2F3b474334b068C95687f4FcE; + bytes32 etherHashSum = 0x984202f6c36a048a80e993557555488e5ae13ff86f2dfbcde698aacd0a7d4eb4; + bytes32 hashSum = 0x06a7e0b6224a17f3938fef1f9ea5c3de949134a66cf8cb8483b76449714a4504; //Arb Testnet variables address linkArb = 0xb1D4538B4571d411F07960EF2838Ce337FE1E80E; @@ -157,7 +159,7 @@ contract ProtocolTestnet is Test { address ProxyOwner = makeAddr("ProxyOwner"); address Tester = makeAddr("Tester"); address User = makeAddr("User"); - address Messenger = makeAddr("Messenger"); + address Messenger = 0x11111003F38DfB073C6FeE2F5B35A0e57dAc4715; address LP = makeAddr("LiquidityProvider"); address defaultSender = 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38; address subOwnerBase = 0xDddDDb8a8E41C194ac6542a0Ad7bA663A72741E0; @@ -397,8 +399,11 @@ contract ProtocolTestnet is Test { wChild = ConceroChildPool(payable(address(childProxy))); + //====== Wrap the proxy as the implementation + opDst = Orchestrator(address(proxyDst)); + //=== Arbitrum Contracts - vm.makePersistent(address(proxyDst)); + vm.makePersistent(address(opDst)); vm.makePersistent(address(dexDst)); vm.makePersistent(address(child)); vm.makePersistent(address(conceroDst)); @@ -412,9 +417,6 @@ contract ProtocolTestnet is Test { vm.prank(ProxyOwner); proxyInterfaceChild.upgradeToAndCall(address(child), ""); - //====== Wrap the proxy as the implementation - opDst = Orchestrator(address(proxyDst)); - //====== Set the DEXes routers vm.prank(defaultSender); opDst.setDexRouterAddress(address(mockArb), 1); @@ -443,11 +445,18 @@ contract ProtocolTestnet is Test { ///======= Infra Allowance vm.startPrank(defaultSender); - op.setDstConceroPool(arbChainSelector, address(childProxy)); + op.setDstConceroPool(arbChainSelector, address(wChild)); assertEq(op.s_poolReceiver(arbChainSelector), address(wChild)); op.setConceroContract(arbChainSelector, address(proxyDst)); + op.setClfPremiumFees(10344971235874465080, 1847290640394088); + op.setDonHostedSecretsVersion(1720259252); + op.setDonHostedSecretsSlotID(3); + op.setDstJsHashSum(hashSum); + op.setSrcJsHashSum(hashSum); + op.setEthersHashSum(etherHashSum); + vm.stopPrank(); vm.startPrank(address(subOwnerBase)); @@ -474,14 +483,22 @@ contract ProtocolTestnet is Test { ///======= Infra Allowance vm.startPrank(defaultSender); - opDst.setDstConceroPool(baseChainSelector, address(wChild)); - assertEq(opDst.s_poolReceiver(baseChainSelector), address(wChild)); + opDst.setDstConceroPool(baseChainSelector, address(wMaster)); + assertEq(opDst.s_poolReceiver(baseChainSelector), address(wMaster)); opDst.setConceroContract(baseChainSelector, address(op)); + + opDst.setClfPremiumFees(3478487238524512106, 4000000000000000); + opDst.setDonHostedSecretsVersion(1718547517); + opDst.setDonHostedSecretsSlotID(3); + opDst.setDstJsHashSum(hashSum); + opDst.setSrcJsHashSum(hashSum); + opDst.setEthersHashSum(etherHashSum); vm.stopPrank(); vm.startPrank(address(subOwnerArb)); functionsRouterArb.addConsumer(53, address(opDst)); + functionsRouterArb.addConsumer(53, address(conceroDst)); vm.stopPrank(); vm.prank(0x4281eCF07378Ee595C564a59048801330f3084eE); @@ -1141,7 +1158,50 @@ contract ProtocolTestnet is Test { // assertTrue(op.s_latestLinkNativeRate() > 0); } + //Reverting because of an Invalid Opcode + event UnconfirmedTXAdded(bytes32 indexed ccipMessageId, address sender, address recipient, uint256 amount, IStorage.CCIPToken token, uint64 srcChainSelector); + function test_addUnconfirmedTX() public setters { + vm.selectFork(arbitrumTestFork); + + /////////////////////////// SWAP DATA MOCKED \\\\\\\\\\\\\\\\\\\\\\\\\\\\ + + uint amountIn = 1*10**17; + uint amountOutMin = 350*10**6; + address[] memory path = new address[](2); + path[0] = address(wEth); + path[1] = address(aUSDC); + address to = address(op); + uint deadline = block.timestamp + 1800; + + IDexSwap.SwapData[] memory swapData = new IDexSwap.SwapData[](1); + swapData[0] = IDexSwap.SwapData({ + dexType: IDexSwap.DexType.UniswapV2, + fromToken: address(wEth), + fromAmount: amountIn, + toToken: address(tUSDC), + toAmount: amountOutMin, + toAmountMin: amountOutMin, + dexData: abi.encode(mockBase, path, to, deadline) + }); + + /////////////////////////// FUNCTION INPUT MOCKED \\\\\\\\\\\\\\\\\\\\\\\\\\\\ + bytes32 ccipId = 0xb41f78fe0c25b7fa0b18ade5bdc972f4163eae5b2d2b1e19d104b11c7bfaf9a1; + address sender = 0x5cb738DAe833Ec21fe65ae1719fAd8ab8cE7f23D; + address recipient = 0x5cb738DAe833Ec21fe65ae1719fAd8ab8cE7f23D; + uint256 amount = 10000000; + uint8 token = 0; + + vm.prank(Messenger); + vm.expectEmit(); + emit UnconfirmedTXAdded(ccipId, sender, recipient, amount, IStorage.CCIPToken(token), baseChainSelector); + opDst.addUnconfirmedTX(ccipId, sender, recipient, amount, baseChainSelector, IStorage.CCIPToken(token), block.number, abi.encode(swapData[0])); + } + + function test_getSrcTotalFeeInUsdcViaDelegateCall() public setters { + uint256 fee = op.getSrcTotalFeeInUsdc(IStorage.CCIPToken.bnm, arbChainSelector, 10*10**6); + assertEq(fee, 0); + } //////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// AUTOMATION MODULE /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol index 32651e7c2..bebeae667 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol @@ -188,8 +188,13 @@ contract ParentPoolTest is Test { vm.startPrank(Orchestrator); vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_CallerIsNotTheProxy.selector, address(masterPool))); masterPool.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(this)); - vm.stopPrank(); + + vm.prank(Tester); + usdc.transfer(address(wMaster), USDC_INITIAL_BALANCE); + vm.prank(Orchestrator); + wMaster.orchestratorLoan(address(usdc), USDC_INITIAL_BALANCE, address(this)); + } //It will revert on ccip call @@ -204,10 +209,16 @@ contract ParentPoolTest is Test { vm.prank(Tester); usdc.approve(address(wMaster), allowedAmountToDeposit); + uint256 capNow = wMaster.getMaxCap(); + assertEq(capNow, 0); + //CCIP being called means deposit went through, so the purpose is fulfilled vm.prank(Tester); vm.expectRevert(); wMaster.depositLiquidity(allowedAmountToDeposit); + + uint256 inUse = wMaster.getUsdcInUse(); + assertEq(inUse, 0); } error ConceroParentPool_AmountBelowMinimum(uint256 amount); @@ -252,4 +263,10 @@ contract ParentPoolTest is Test { emit ConceroParentPool_RedistributionStarted(0); //requestId == 0 because CLF is disabled wMaster.removePools(mockDestinationChainSelector); } + + function test_startWithdrawRevert() public { + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InsufficientBalance.selector)); + wMaster.startWithdrawal(10*10**18); + } + } diff --git a/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol index ba8e05104..d144573f5 100644 --- a/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol @@ -14,7 +14,7 @@ contract ChildPoolStorage { ///STORAGE/// ///////////// ///@notice array of chain IDS of Pools to receive Liquidity through `ccipSend` function - uint64[] s_poolsToDistribute; + uint64[] s_poolChainSelectors; ///@notice Mapping to keep track of allowed pool senders mapping(uint64 chainSelector => mapping(address conceroContract => uint256)) public s_contractsToReceiveFrom; From fb521753d38ecadad0efa25a58790c3e3200ba7d Mon Sep 17 00:00:00 2001 From: Barba Date: Mon, 15 Jul 2024 15:58:27 -0300 Subject: [PATCH 13/17] Pool Fees --- .../MainnetFork/ProtocolMainnet.t.sol | 7 +- .../hardhat/contracts/ConceroParentPool.sol | 150 +++++++++--------- 2 files changed, 79 insertions(+), 78 deletions(-) diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index dd4f60ca4..19819d641 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -473,14 +473,14 @@ contract ProtocolMainnet is Test { //====== Setters ///== Pools vm.startPrank(Tester); - wMaster.setPools(arbChainSelector, address(childProxy), false); + wMaster.setPools(arbChainSelector, address(wChild), false); assertEq(wMaster.s_poolToSendTo(arbChainSelector), address(wChild)); wMaster.setConceroContractSender(arbChainSelector, address(wChild), 1); assertEq(wMaster.s_contractsToReceiveFrom(arbChainSelector, address(wChild)), 1); - wMaster.setConceroContractSender(arbChainSelector, address(conceroDst), 1); - assertEq(wMaster.s_contractsToReceiveFrom(arbChainSelector, address(conceroDst)), 1); + wMaster.setConceroContractSender(arbChainSelector, address(opDst), 1); + assertEq(wMaster.s_contractsToReceiveFrom(arbChainSelector, address(opDst)), 1); wMaster.setDonHostedSecretsSlotId(slotId); @@ -500,6 +500,7 @@ contract ProtocolMainnet is Test { assertEq(op.s_conceroContracts(arbChainSelector), address(opDst)); vm.stopPrank(); + ///== Chainlink Functions vm.startPrank(baseSubOwner); functionsRouterBase.addConsumer(14, address(op)); functionsRouterBase.addConsumer(14, address(wMaster)); diff --git a/packages/hardhat/contracts/ConceroParentPool.sol b/packages/hardhat/contracts/ConceroParentPool.sol index a34bc07c7..6db4c4fe4 100644 --- a/packages/hardhat/contracts/ConceroParentPool.sol +++ b/packages/hardhat/contracts/ConceroParentPool.sol @@ -231,10 +231,10 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { if (numberOfPools < ALLOWED) revert ConceroParentPool_ThereIsNoPoolToDistribute(); - // uint256 depositFee = _calculateDepositTransactionFee(_usdcAmount); - // uint256 depositMinusFee = _usdcAmount - _convertToUSDCTokenDecimals(depositFee); + uint256 depositFee = _calculateDepositTransactionFee(_usdcAmount); + uint256 depositMinusFee = _usdcAmount - _convertToUSDCTokenDecimals(depositFee); - uint256 amountToDistribute = ((_usdcAmount * PRECISION_HANDLER) / (numberOfPools + 1)) / PRECISION_HANDLER; + uint256 amountToDistribute = ((depositMinusFee * PRECISION_HANDLER) / (numberOfPools + 1)) / PRECISION_HANDLER; bytes[] memory args = new bytes[](2); args[0] = abi.encodePacked(s_hashSum); @@ -246,13 +246,13 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { liquidityProvider: msg.sender, usdcBeforeRequest: i_USDC.balanceOf(address(this)) + s_loansInUse, lpSupplyBeforeRequest: i_lp.totalSupply(), - amount: _usdcAmount + amount: depositMinusFee }); emit ConceroParentPool_SuccessfulDeposited(msg.sender, _usdcAmount, i_USDC); i_USDC.safeTransferFrom(msg.sender, address(this), _usdcAmount); - // i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(depositFee)); + i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(depositFee)); _distributeLiquidity(amountToDistribute); } @@ -298,16 +298,16 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { delete s_pendingWithdrawRequests[msg.sender]; - // uint256 withdrawFees = _calculateWithdrawTransactionsFee(withdraw.amountEarned); - // uint256 withdrawAmountMinusFees = withdraw.amountEarned - _convertToUSDCTokenDecimals(withdrawFees); + uint256 withdrawFees = _calculateWithdrawTransactionsFee(withdraw.amountEarned); + uint256 withdrawAmountMinusFees = withdraw.amountEarned - _convertToUSDCTokenDecimals(withdrawFees); - emit ConceroParentPool_Withdrawn(msg.sender, address(i_USDC), withdraw.amountEarned); + emit ConceroParentPool_Withdrawn(msg.sender, address(i_USDC), withdrawAmountMinusFees); IERC20(i_lp).safeTransferFrom(msg.sender, address(this), withdraw.amountToBurn); i_lp.burn(withdraw.amountToBurn); - // i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(withdrawFees)); - i_USDC.safeTransfer(msg.sender, withdraw.amountEarned); + i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(withdrawFees)); + i_USDC.safeTransfer(msg.sender, withdrawAmountMinusFees); } /** @@ -646,71 +646,71 @@ contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { emit ConceroParentPool_RequestUpdated(_liquidityProvider); } - // function _calculateDepositTransactionFee(uint256 _amountToDistribute) internal view returns(uint256 _totalUSDCCost){ - // uint256 numberOfPools = s_poolChainSelectors.length; - // uint256 costOfLinkForLiquidityDistribution; - // uint256 premiumFee = Orchestrator(i_infraProxy).clfPremiumFees(BASE_CHAIN_SELECTOR); - // uint256 lastNativeUSDCRate = Orchestrator(i_infraProxy).s_latestNativeUsdcRate(); - // uint256 lastLinkUSDCRate = Orchestrator(i_infraProxy).s_latestLinkUsdcRate(); - // uint256 lastBaseGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); - - // for(uint256 i; i < numberOfPools; ){ - // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), s_poolToSendTo[s_poolChainSelectors[i]]); - - // //Link cost for all transactions - // costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(s_poolChainSelectors[i], evm2AnyMessage); - // unchecked { - // ++i; - // } - // } - - // //_totalUSDCCost - // // Pools.length x Calls to distribute liquidity - // // 1x Functions request sent - // // 1x Callback Writing to storage - // _totalUSDCCost = ((costOfLinkForLiquidityDistribution + premiumFee) * lastLinkUSDCRate) + ((WRITE_FUNCTIONS_COST * lastBaseGasPrice) * lastNativeUSDCRate); - // } - - // function _calculateWithdrawTransactionsFee(uint256 _amountToReceive) internal view returns(uint256 _totalUSDCCost){ - // uint256 numberOfPools = s_poolChainSelectors.length; - // uint256 premiumFee = Orchestrator(i_infraProxy).clfPremiumFees(BASE_CHAIN_SELECTOR); - // uint256 baseLastGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); - // uint256 lastNativeUSDCRate = Orchestrator(i_infraProxy).s_latestNativeUsdcRate(); - // uint256 lastLinkUSDCRate = Orchestrator(i_infraProxy).s_latestLinkUsdcRate(); - - // uint256 costOfLinkForLiquidityWithdraw; - // uint256 costOfCCIPSendToPoolExecution; - - // for(uint256 i; i < numberOfPools; ){ - // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToReceive, address(this)); - - // //Link cost for all transactions - // costOfLinkForLiquidityWithdraw += IRouterClient(i_ccipRouter).getFee(BASE_CHAIN_SELECTOR, evm2AnyMessage); //here the chainSelector must be Base's? - // //USDC costs for all writing from the above transactions - // costOfCCIPSendToPoolExecution += Orchestrator(i_infraProxy).s_lastGasPrices(s_poolChainSelectors[i]) * WRITE_FUNCTIONS_COST; - // unchecked { - // ++i; - // } - // } - - // // _totalUSDCCost == - // // 2x Functions Calls - Link Cost - // // Pools.length x Calls - Link Cost - // // Base's gas Cost of callback - // // Pools.length x Calls to ccipSendToPool Child Pool function - // // Automation Costs? - // // SLOAD - 800 - // // ++i - 5 - // // Comparing = 3 - // // STORE - 5_000 - // // Array Reduction - 5_000 - // // gasOverhead - 80_000 - // // Nodes Premium - 50% - // uint256 arrayLength = i_automation.getPendingWithdrawRequestsLength(); - - // uint256 automationCost = (((ITERATION_COSTS * arrayLength) + ARRAY_MANIPULATION + AUTOMATION_OVERHEARD) * NODE_PREMIUM) / 100; - // _totalUSDCCost = (((premiumFee * 2) + costOfLinkForLiquidityWithdraw + automationCost) * lastLinkUSDCRate) + ((WRITE_FUNCTIONS_COST * baseLastGasPrice) * lastNativeUSDCRate) + costOfCCIPSendToPoolExecution; - // } + function _calculateDepositTransactionFee(uint256 _amountToDistribute) internal view returns(uint256 _totalUSDCCost){ + uint256 numberOfPools = s_poolChainSelectors.length; + uint256 costOfLinkForLiquidityDistribution; + uint256 premiumFee = Orchestrator(i_infraProxy).clfPremiumFees(BASE_CHAIN_SELECTOR); + uint256 lastNativeUSDCRate = Orchestrator(i_infraProxy).s_latestNativeUsdcRate(); + uint256 lastLinkUSDCRate = Orchestrator(i_infraProxy).s_latestLinkUsdcRate(); + uint256 lastBaseGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); + + for(uint256 i; i < numberOfPools; ){ + Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(s_poolChainSelectors[i], address(i_USDC), (_amountToDistribute / (numberOfPools+1))); + + //Link cost for all transactions + costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(s_poolChainSelectors[i], evm2AnyMessage); + unchecked { + ++i; + } + } + + //_totalUSDCCost + // Pools.length x Calls to distribute liquidity + // 1x Functions request sent + // 1x Callback Writing to storage + _totalUSDCCost = ((costOfLinkForLiquidityDistribution + premiumFee) * lastLinkUSDCRate) + ((WRITE_FUNCTIONS_COST * lastBaseGasPrice) * lastNativeUSDCRate); + } + + function _calculateWithdrawTransactionsFee(uint256 _amountToReceive) internal view returns(uint256 _totalUSDCCost){ + uint256 numberOfPools = s_poolChainSelectors.length; + uint256 premiumFee = Orchestrator(i_infraProxy).clfPremiumFees(BASE_CHAIN_SELECTOR); + uint256 baseLastGasPrice = tx.gasprice; //Orchestrator(i_infraProxy).s_lastGasPrices(BASE_CHAIN_SELECTOR); + uint256 lastNativeUSDCRate = Orchestrator(i_infraProxy).s_latestNativeUsdcRate(); + uint256 lastLinkUSDCRate = Orchestrator(i_infraProxy).s_latestLinkUsdcRate(); + + uint256 costOfLinkForLiquidityWithdraw; + uint256 costOfCCIPSendToPoolExecution; + + for(uint256 i; i < numberOfPools; ){ + Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(s_poolChainSelectors[i], address(i_USDC), _amountToReceive); + + //Link cost for all transactions + costOfLinkForLiquidityWithdraw += IRouterClient(i_ccipRouter).getFee(s_poolChainSelectors[i], evm2AnyMessage); + //USDC costs for all writing from the above transactions + costOfCCIPSendToPoolExecution += Orchestrator(i_infraProxy).s_lastGasPrices(s_poolChainSelectors[i]) * WRITE_FUNCTIONS_COST; + unchecked { + ++i; + } + } + + // _totalUSDCCost == + // 2x Functions Calls - Link Cost + // Pools.length x Calls - Link Cost + // Base's gas Cost of callback + // Pools.length x Calls to ccipSendToPool Child Pool function + // Automation Costs? + // SLOAD - 800 + // ++i - 5 + // Comparing = 3 + // STORE - 5_000 + // Array Reduction - 5_000 + // gasOverhead - 80_000 + // Nodes Premium - 50% + uint256 arrayLength = i_automation.getPendingWithdrawRequestsLength(); + + uint256 automationCost = (((ITERATION_COSTS * arrayLength) + ARRAY_MANIPULATION + AUTOMATION_OVERHEARD) * NODE_PREMIUM) / 100; + _totalUSDCCost = (((premiumFee * 2) + costOfLinkForLiquidityWithdraw + automationCost) * lastLinkUSDCRate) + ((WRITE_FUNCTIONS_COST * baseLastGasPrice) * lastNativeUSDCRate) + costOfCCIPSendToPoolExecution; + } /////////////////////////// ///VIEW & PURE FUNCTIONS/// From dc823e0112beaddd731bdc219f9369e790f18095 Mon Sep 17 00:00:00 2001 From: Barba Date: Wed, 17 Jul 2024 22:07:30 -0300 Subject: [PATCH 14/17] Enable Native Swap --- .../MainnetFork/ProtocolMainnet.t.sol | 56 +++++++++++++++++++ packages/hardhat/contracts/Constants.sol | 14 +++++ packages/hardhat/contracts/Orchestrator.sol | 43 +++++++++++++- 3 files changed, 111 insertions(+), 2 deletions(-) diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index 19819d641..2d194d50d 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -1030,6 +1030,33 @@ contract ProtocolMainnet is Test { op.swap(swapData, User); } + function test_swapEtherUniV3SingleMock() public { + vm.selectFork(baseMainFork); + uint256 amountIn = 1*10**17; + uint256 amountOut = 350*10*6; + + vm.deal(User, amountIn); + + IDexSwap.SwapData[] memory swapData = new IDexSwap.SwapData[](1); + + swapData[0] = IDexSwap.SwapData({ + dexType: IDexSwap.DexType.UniswapV3Single, + fromToken: address(0), + fromAmount: amountIn, + toToken: address(mUSDC), + toAmount: amountOut, + toAmountMin: amountOut, + dexData: abi.encode(uniswapV3, 500, 0, block.timestamp + 1800) + }); + + vm.startPrank(User); + + op.swap{value: amountIn}(swapData, User); + + assertEq(address(op).balance, 100000000000000); + assertTrue(mUSDC.balanceOf(address(User)) > USDC_INITIAL_BALANCE + amountOut); + } + function test_swapSushiV3MultiMock() public { helper(); @@ -1211,6 +1238,35 @@ contract ProtocolMainnet is Test { op.swap(swapData, User); } + function test_swapEtherUniV3MultiMock() public { + vm.selectFork(baseMainFork); + vm.deal(User, 1*10**18); + + uint24 poolFee = 500; + uint256 amountIn = 1*10**17; + uint256 amountOut = 1*10**16; + + bytes memory path = abi.encodePacked(wEth, poolFee, mUSDC, poolFee, wEth); + + IDexSwap.SwapData[] memory swapData = new IDexSwap.SwapData[](1); + swapData[0] = IDexSwap.SwapData({ + dexType: IDexSwap.DexType.UniswapV3Multi, + fromToken: address(0), + fromAmount: amountIn, + toToken: address(wEth), + toAmount: amountOut, + toAmountMin: amountOut, + dexData: abi.encode(uniswapV3, path, block.timestamp + 1800) + }); + + vm.startPrank(User); + op.swap{value: amountIn}(swapData, User); + + assertEq(User.balance, 1*10**18 - amountIn); + assertEq(address(op).balance, 100000000000000); + assertTrue(wEth.balanceOf(User) > amountOut); + } + function test_revertSwapUniV3MultiMockInvalidPath() public { helper(); diff --git a/packages/hardhat/contracts/Constants.sol b/packages/hardhat/contracts/Constants.sol index 2aa8f993a..c4812960d 100644 --- a/packages/hardhat/contracts/Constants.sol +++ b/packages/hardhat/contracts/Constants.sol @@ -20,3 +20,17 @@ uint64 constant CHAIN_SELECTOR_ARBITRUM = 4949039107694359620; uint64 constant CHAIN_SELECTOR_BASE = 15971525489660198786; uint64 constant CHAIN_SELECTOR_OPTIMISM = 3734403246176062136; uint64 constant CHAIN_SELECTOR_POLYGON = 4051577828743386545; + +uint64 constant CHAIN_ID_AVALANCHE = 43114; +uint64 constant CHAIN_ID_ETHEREUM = 1; +uint64 constant CHAIN_ID_ARBITRUM = 42161; +uint64 constant CHAIN_ID_BASE = 8453; +uint64 constant CHAIN_ID_OPTIMISM = 10; +uint64 constant CHAIN_ID_POLYGON = 137; + +address constant WRAPPED_NATIVE_AVALANCHE = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7; +address constant WRAPPED_NATIVE_ETHEREUM = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; +address constant WRAPPED_NATIVE_ARBITRUM = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; +address constant WRAPPED_NATIVE_BASE = 0x4200000000000000000000000000000000000006; +address constant WRAPPED_NATIVE_OPTIMISM = 0x4200000000000000000000000000000000000006; +address constant WRAPPED_NATIVE_POLYGON = 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270; \ No newline at end of file diff --git a/packages/hardhat/contracts/Orchestrator.sol b/packages/hardhat/contracts/Orchestrator.sol index 24f1b9579..4de76d03c 100644 --- a/packages/hardhat/contracts/Orchestrator.sol +++ b/packages/hardhat/contracts/Orchestrator.sol @@ -11,6 +11,16 @@ import {LibConcero} from "./Libraries/LibConcero.sol"; import {IOrchestrator, IOrchestratorViewDelegate} from "./Interfaces/IOrchestrator.sol"; import {ConceroCommon} from "./ConceroCommon.sol"; import {USDC_ARBITRUM, USDC_BASE, USDC_OPTIMISM, USDC_POLYGON, CHAIN_SELECTOR_ARBITRUM, CHAIN_SELECTOR_BASE, CHAIN_SELECTOR_OPTIMISM, CHAIN_SELECTOR_POLYGON} from "./Constants.sol"; +import {CHAIN_ID_AVALANCHE, WRAPPED_NATIVE_AVALANCHE, CHAIN_ID_ETHEREUM, WRAPPED_NATIVE_ETHEREUM, CHAIN_ID_ARBITRUM, WRAPPED_NATIVE_ARBITRUM, CHAIN_ID_BASE, WRAPPED_NATIVE_BASE, CHAIN_ID_OPTIMISM, WRAPPED_NATIVE_OPTIMISM, CHAIN_ID_POLYGON, WRAPPED_NATIVE_POLYGON} from "./Constants.sol"; + +//////////////////////////////////// +/////////////INTERFACES///////////// +//////////////////////////////////// +interface IWETH is IERC20 { + function deposit() external payable; + + function withdraw(uint256) external; +} /////////////////////////////// /////////////ERROR///////////// @@ -29,6 +39,8 @@ error Orchestrator_InvalidSwapData(); error Orchestrator_InvalidSwapEtherData(); ///@notice error emitted when the token to bridge is not USDC error Orchestrator_InvalidBridgeToken(); +///@notice error emitted when the token is not supported +error Orchestrator_ChainNotSupported(); contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, StorageSetters { using SafeERC20 for IERC20; @@ -232,11 +244,18 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage LibConcero.transferFromERC20(fromToken, msg.sender, address(this), fromAmount); if (isFeesNeeded) swapData[0].fromAmount -= (fromAmount / CONCERO_FEE_FACTOR); } else { - if (isFeesNeeded) _nativeAmount -= (_nativeAmount / CONCERO_FEE_FACTOR); + if (isFeesNeeded) swapData[0].fromAmount = _nativeAmount - (_nativeAmount / CONCERO_FEE_FACTOR); + + if (swapData[0].dexType != IDexSwap.DexType.UniswapV2Ether){ + address wrapped = getWrappedNative(); + swapData[0].fromToken = address(wrapped); + IWETH(wrapped).deposit{value: swapData[0].fromAmount}(); + } } + //Now we can remove _nativeAmount / swapData[0].fromAmount from conceroEntry call. (bool swapSuccess, bytes memory swapError) = i_dexSwap.delegatecall( - abi.encodeWithSelector(IDexSwap.conceroEntry.selector, swapData, _nativeAmount, _receiver) + abi.encodeWithSelector(IDexSwap.conceroEntry.selector, swapData, swapData[0].fromAmount, _receiver) ); if (swapSuccess == false) revert Orchestrator_UnableToCompleteDelegateCall(swapError); @@ -259,6 +278,26 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage } } + function getWrappedNative() internal view returns (address _wrappedAddress) { + uint256 chainId = block.chainid; + + if (chainId == CHAIN_ID_AVALANCHE) { + _wrappedAddress = WRAPPED_NATIVE_AVALANCHE; + } else if (chainId == CHAIN_ID_ETHEREUM) { + _wrappedAddress = WRAPPED_NATIVE_ETHEREUM; + } else if (chainId == CHAIN_ID_ARBITRUM) { + _wrappedAddress = WRAPPED_NATIVE_ARBITRUM; + } else if (chainId == CHAIN_ID_BASE) { + _wrappedAddress = WRAPPED_NATIVE_BASE; + } else if (chainId == CHAIN_ID_OPTIMISM) { + _wrappedAddress = WRAPPED_NATIVE_OPTIMISM; + } else if (chainId == CHAIN_ID_POLYGON) { + _wrappedAddress = WRAPPED_NATIVE_POLYGON; + } else { + revert Orchestrator_ChainNotSupported(); + } + } + /////////////////////////// ///VIEW & PURE FUNCTIONS/// /////////////////////////// From bca995f7bdb4d6a55c8da095ed911ae4c8e86aa7 Mon Sep 17 00:00:00 2001 From: Barba Date: Wed, 17 Jul 2024 22:32:13 -0300 Subject: [PATCH 15/17] Implemente Test on Arbitrum --- .../MainnetFork/ProtocolMainnet.t.sol | 31 +++++++++++++++++-- packages/hardhat/contracts/DexSwap.sol | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol index 2d194d50d..6254eccaa 100644 --- a/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/MainnetFork/ProtocolMainnet.t.sol @@ -361,7 +361,7 @@ contract ProtocolMainnet is Test { //===== Arbitrum Routers uniswapV2Arb = IUniswapV2Router02(0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24); sushiV2Arb = IUniswapV2Router02(0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506); - uniswapV3Arb = ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45); + uniswapV3Arb = ISwapRouter02(0xE592427A0AEce92De3Edee1F18E0157C05861564); sushiV3Arb = ISwapRouter(0x8A21F6768C1f8075791D08546Dadf6daA0bE820c); //===== Arbitrum Tokens @@ -1030,7 +1030,7 @@ contract ProtocolMainnet is Test { op.swap(swapData, User); } - function test_swapEtherUniV3SingleMock() public { + function test_swapEtherUniV3SingleBase() public { vm.selectFork(baseMainFork); uint256 amountIn = 1*10**17; uint256 amountOut = 350*10*6; @@ -1057,6 +1057,33 @@ contract ProtocolMainnet is Test { assertTrue(mUSDC.balanceOf(address(User)) > USDC_INITIAL_BALANCE + amountOut); } + function test_swapEtherUniV3SingleArb() public { + vm.selectFork(arbitrumMainFork); + uint256 amountIn = 1*10**17; + uint256 amountOut = 350*10*6; + + vm.deal(User, amountIn); + + IDexSwap.SwapData[] memory swapData = new IDexSwap.SwapData[](1); + + swapData[0] = IDexSwap.SwapData({ + dexType: IDexSwap.DexType.UniswapV3Single, + fromToken: address(0), + fromAmount: amountIn, + toToken: address(aUSDC), + toAmount: amountOut, + toAmountMin: amountOut, + dexData: abi.encode(uniswapV3Arb, 500, 0, block.timestamp + 1800) + }); + + vm.startPrank(User); + + opDst.swap{value: amountIn}(swapData, User); + + assertEq(address(opDst).balance, 100000000000000); + assertTrue(aUSDC.balanceOf(address(User)) > USDC_INITIAL_BALANCE + amountOut); + } + function test_swapSushiV3MultiMock() public { helper(); diff --git a/packages/hardhat/contracts/DexSwap.sol b/packages/hardhat/contracts/DexSwap.sol index f89e0876e..2c4d94215 100644 --- a/packages/hardhat/contracts/DexSwap.sol +++ b/packages/hardhat/contracts/DexSwap.sol @@ -220,7 +220,7 @@ contract DexSwap is IDexSwap, Storage { recipient: _recipient, deadline: deadline, amountIn: _swapData.fromAmount, - amountOutMinimum: _swapData.toAmountMin, + amountOutMinimum: _swapData.toAmountMin, sqrtPriceLimitX96: sqrtPriceLimitX96 }); From 7cb64ea9cb29fe965f92a0ab8b2145b86eb25369 Mon Sep 17 00:00:00 2001 From: Oleg Kirillovich Date: Thu, 18 Jul 2024 19:00:33 +0100 Subject: [PATCH 16/17] todos --- packages/hardhat/contracts/Orchestrator.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/hardhat/contracts/Orchestrator.sol b/packages/hardhat/contracts/Orchestrator.sol index 4de76d03c..3c55187d5 100644 --- a/packages/hardhat/contracts/Orchestrator.sol +++ b/packages/hardhat/contracts/Orchestrator.sol @@ -135,6 +135,7 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage if (srcSwapData[srcSwapData.length - 1].toToken != getToken(bridgeData.tokenType, i_chainIndex)) revert Orchestrator_InvalidSwapData(); //Swap -> money come back to this contract + // todo: 0 -> msg.value uint256 amountReceivedFromSwap = _swap(srcSwapData, 0, false, address(this)); bridgeData.amount = amountReceivedFromSwap; @@ -233,6 +234,7 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage ////////////////////////// /// INTERNAL FUNCTIONS /// ////////////////////////// + function _swap(IDexSwap.SwapData[] memory swapData, uint256 _nativeAmount, bool isFeesNeeded, address _receiver) internal returns (uint256) { address fromToken = swapData[0].fromToken; uint256 fromAmount = swapData[0].fromAmount; @@ -246,7 +248,7 @@ contract Orchestrator is IFunctionsClient, IOrchestrator, ConceroCommon, Storage } else { if (isFeesNeeded) swapData[0].fromAmount = _nativeAmount - (_nativeAmount / CONCERO_FEE_FACTOR); - if (swapData[0].dexType != IDexSwap.DexType.UniswapV2Ether){ + if (swapData[0].dexType != IDexSwap.DexType.UniswapV2Ether) { address wrapped = getWrappedNative(); swapData[0].fromToken = address(wrapped); IWETH(wrapped).deposit{value: swapData[0].fromAmount}(); From 8bf4c9e2809fe6d0c3d89897d453f0a33c028dfd Mon Sep 17 00:00:00 2001 From: Barba Date: Fri, 19 Jul 2024 10:16:28 -0300 Subject: [PATCH 17/17] Adjust Constants --- packages/hardhat/contracts/Constants.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hardhat/contracts/Constants.sol b/packages/hardhat/contracts/Constants.sol index c4812960d..66df6a132 100644 --- a/packages/hardhat/contracts/Constants.sol +++ b/packages/hardhat/contracts/Constants.sol @@ -33,4 +33,4 @@ address constant WRAPPED_NATIVE_ETHEREUM = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C7 address constant WRAPPED_NATIVE_ARBITRUM = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; address constant WRAPPED_NATIVE_BASE = 0x4200000000000000000000000000000000000006; address constant WRAPPED_NATIVE_OPTIMISM = 0x4200000000000000000000000000000000000006; -address constant WRAPPED_NATIVE_POLYGON = 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270; \ No newline at end of file +address constant WRAPPED_NATIVE_POLYGON = 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270;