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/coverage.txt b/packages/foundry/coverage.txt deleted file mode 100644 index d1254a6ce..000000000 --- a/packages/foundry/coverage.txt +++ /dev/null @@ -1,408 +0,0 @@ -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) -- 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 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) -- 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..c2a121067 --- /dev/null +++ b/packages/foundry/coverageTwo.txt @@ -0,0 +1,304 @@ +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: + +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: + - 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) + - 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/script/ChildPoolDeploy.s.sol b/packages/foundry/script/ChildPoolDeploy.s.sol index d357e4da2..56fc7b336 100644 --- a/packages/foundry/script/ChildPoolDeploy.s.sol +++ b/packages/foundry/script/ChildPoolDeploy.s.sol @@ -9,22 +9,18 @@ contract ChildPoolDeploy is Script { function run( address _orchestratorProxy, - address _masterPoolProxyAddress, address _childProxy, address _link, address _ccipRouter, - uint64 _destinationChainSelector, address _usdc, address _owner ) public returns(ConceroChildPool child){ vm.startBroadcast(); child = new ConceroChildPool( _orchestratorProxy, - _masterPoolProxyAddress, _childProxy, _link, _ccipRouter, - _destinationChainSelector, _usdc, _owner ); 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 ffc3878d3..7fc28c2df 100644 --- a/packages/foundry/script/TestnetChildPoolDeploy.s.sol +++ b/packages/foundry/script/TestnetChildPoolDeploy.s.sol @@ -7,11 +7,9 @@ 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; - uint64 _destinationChainSelector = 10344971235874465080; address _usdc = 0x036CbD53842c5426634e7929541eC2318f3dCF7e; address _owner = 0x5FA769922a6428758fb44453815e2c436c57C3c7; @@ -19,11 +17,9 @@ contract TestnetChildPoolDeploy is Script { vm.startBroadcast(); child = new ConceroChildPool( _orchestratorProxy, - _masterPoolProxyAddress, _childProxy, _link, - _ccipRouter, - _destinationChainSelector, + _ccipRouter, _usdc, _owner ); 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 ada25a612..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,11 +365,9 @@ contract InfraIntegration is Test { child = childDeployArbitrum.run( address(proxyDst), - address(masterProxy), address(childProxy), link, ccipRouterLocalDst, - localChainSelector, address(mUSDC), Tester ); @@ -409,7 +407,7 @@ contract InfraIntegration is Test { //Parent Pool wMaster.setConceroContractSender(localChainSelector, address(wChild), 1); - wMaster.setPoolsToSend(localChainSelector, address(wChild)); + 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 c267dc6a0..6254eccaa 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,10 +115,9 @@ contract ProtocolMainnet is Test { //==== Wrapped contract Orchestrator op; Orchestrator opDst; - ParentPool wMaster; + 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; @@ -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)); @@ -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 @@ -425,11 +425,9 @@ contract ProtocolMainnet is Test { child = childDeployArbitrum.run( address(proxyDst), - address(masterProxy), address(childProxy), linkArb, ccipRouterArb, - baseChainSelector, address(aUSDC), Tester ); @@ -475,14 +473,14 @@ contract ProtocolMainnet is Test { //====== Setters ///== Pools vm.startPrank(Tester); - wMaster.setPoolsToSend(arbChainSelector, address(childProxy)); + 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); @@ -502,7 +500,8 @@ contract ProtocolMainnet is Test { assertEq(op.s_conceroContracts(arbChainSelector), address(opDst)); vm.stopPrank(); - vm.startPrank(address(subOwner)); + ///== Chainlink Functions + vm.startPrank(baseSubOwner); functionsRouterBase.addConsumer(14, address(op)); functionsRouterBase.addConsumer(14, address(wMaster)); functionsRouterBase.addConsumer(14, address(automation)); @@ -530,7 +529,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(); @@ -735,6 +734,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 =========================================\\ @@ -1028,6 +1030,60 @@ contract ProtocolMainnet is Test { op.swap(swapData, User); } + function test_swapEtherUniV3SingleBase() 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_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(); @@ -1209,6 +1265,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(); @@ -1494,6 +1579,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, @@ -1754,11 +1842,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(); @@ -1776,14 +1864,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 @@ -1791,14 +1879,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 73fa26d22..9306a0485 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"; @@ -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"; @@ -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; @@ -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; @@ -247,6 +249,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), @@ -279,7 +282,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)); @@ -387,19 +390,20 @@ contract ProtocolTestnet is Test { child = childDeployArbitrum.run( address(proxyDst), - address(masterProxy), address(childProxy), linkArb, ccipRouterArb, - baseChainSelector, address(ccipBnMArb), Tester ); 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)); @@ -413,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); @@ -432,7 +433,7 @@ contract ProtocolTestnet is Test { ///======= Pools Allowance vm.startPrank(Tester); - wMaster.setPoolsToSend(arbChainSelector, address(childProxy)); + wMaster.setPools(arbChainSelector, address(childProxy), false); assertEq(wMaster.s_poolToSendTo(arbChainSelector), address(wChild)); wMaster.setConceroContractSender(arbChainSelector, address(wChild), 1); @@ -444,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)); @@ -475,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); @@ -598,12 +614,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(); @@ -748,138 +800,168 @@ 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); - // function test_LiquidityProvidersDepositAndOpenARequest() public setters { - // vm.selectFork(baseTestFork); + 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); - // 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(ConceroParentPool_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 ConceroParentPool_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(ConceroParentPool_MaxCapReached.selector, 50*10**6)); + wMaster.depositLiquidity(depositEnoughAmount); + vm.stopPrank(); + + //======= Increase the CAP + vm.expectEmit(); + vm.prank(Tester); + emit ConceroParentPool_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); - //Callback isn't performed on forked environment + //======= 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(ConceroParentPool_InsufficientBalance.selector)); + wMaster.startWithdrawal(lpTokenUserBalance + 10); + vm.stopPrank(); + + //======= Request Withdraw without any accrued fee + vm.startPrank(LP); + vm.expectEmit(); + 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(ConceroParentPool_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(ConceroParentPool_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(ConceroParentPool_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(ConceroParentPool_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); + //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)); + 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(baseChainSelector, Tester, 10*10**6); + + vm.prank(0x4281eCF07378Ee595C564a59048801330f3084eE); + LinkToken(linkArb).transfer(address(wChild), 10*10**18); + + vm.prank(Messenger); + wChild.ccipSendToPool(baseChainSelector, 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 // function test_PoolFees() public setters { // vm.selectFork(baseTestFork); // uint256 lpBnMBalance = 1000*10**6; @@ -963,7 +1045,7 @@ contract ProtocolTestnet is Test { //////////////////////////////////////////////////////////////////////////////////// error Concero_ItsNotOrchestrator(address); - function test_swapAndBridgeWithoutFunctions() public setters{ + function test_swapAndBridgeTestnet() public setters{ helper(); /////////////////////////// SWAP DATA MOCKED \\\\\\\\\\\\\\\\\\\\\\\\\\\\ @@ -1014,7 +1096,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); @@ -1067,15 +1149,59 @@ 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); // 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/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/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol index 44efaa28f..d2e7f9cca 100644 --- a/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol +++ b/packages/foundry/test/Pos-Upgradeable/UnitTests/ConceroChildPool.t.sol @@ -71,11 +71,9 @@ contract ConceroChildPoolTest is Test { //======= Deploy MasterPool childPool = childDeploy.run( Orchestrator, - address(0), address(childProxy), mockLinkTokenAddress, mockSourceRouter, - mockDestinationChainSelector, address(usdc), Tester ); @@ -158,4 +156,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(mockDestinationChainSelector, 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..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,11 +272,11 @@ 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); - // lp.grantRole(keccak256("MINTER_ROLE"), address(wMaster)); + vm.prank(Tester); + lp.grantRole(keccak256("MINTER_ROLE"), address(wMaster)); } } diff --git a/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol b/packages/foundry/test/Pos-Upgradeable/UnitTests/ParentPool.t.sol index 90859ba3b..bebeae667 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,83 +102,99 @@ 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); - function test_setParentPool() public { + 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); } - //setParentPoolReceiver/// - event ParentPool_PoolReceiverUpdated(uint64 chainSelector, address contractAddress); - function test_setParentPoolReceiver() public { + //setPools/// + event ConceroParentPool_PoolReceiverUpdated(uint64 chainSelector, address contractAddress); + function test_setPools() public { vm.prank(Tester); vm.expectEmit(); - emit ParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + emit ConceroParentPool_PoolReceiverUpdated(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPools(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)); + event ConceroParentPool_RedistributionStarted(bytes32); + function test_revertSetPools() public { + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_NotContractOwner.selector)); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + vm.expectEmit(); + 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)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + vm.expectRevert(abi.encodeWithSelector(ConceroParentPool_InvalidAddress.selector)); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); - vm.expectRevert(abi.encodeWithSelector(ParentPool_InvalidAddress.selector)); - wMaster.setPoolsToSend(mockDestinationChainSelector, address(0)); + 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(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(); + + 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 @@ -187,57 +203,70 @@ contract ParentPoolTest is Test { //===== Add a Fake pool vm.prank(Tester); - wMaster.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress); + wMaster.setPools(mockDestinationChainSelector, mockChildPoolAddress, false); //===== Cap is Zero 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 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.setPoolsToSend(mockDestinationChainSelector, mockChildPoolAddress); + 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.setPoolsToSend(mockDestinationChainSelector, address(mockChildPoolAddress)); + wMaster.setPools(mockDestinationChainSelector, address(mockChildPoolAddress), false); vm.prank(Tester); vm.expectEmit(); - emit ParentPool_ChainAndAddressRemoved(mockDestinationChainSelector); - wMaster.removePoolsFromListOfSenders(mockDestinationChainSelector); + emit ConceroParentPool_ChainAndAddressRemoved(mockDestinationChainSelector); + 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/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..3c84c4431 100644 --- a/packages/hardhat/contracts/ConceroChildPool.sol +++ b/packages/hardhat/contracts/ConceroChildPool.sol @@ -7,9 +7,10 @@ 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"; //////////////////////////////////////////////////////// //////////////////////// ERRORS //////////////////////// @@ -30,8 +31,10 @@ 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 { +contract ConceroChildPool is CCIPReceiver, ChildPoolStorage { using SafeERC20 for IERC20; /////////////////////////////////////////////////////////// @@ -54,10 +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 chain selector - uint64 private immutable i_parentPoolChainSelector; - ///@notice immutable variable to store the MasterPool Proxy address - address private immutable i_parentPoolProxyAddress; ///@notice Contract Owner address immutable i_owner; @@ -72,6 +71,10 @@ 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); + ///@notice event emitted when a pool is removed + event ConceroChildPool_ChainAndAddressRemoved(uint64 chainSelector); /////////////// ///MODIFIERS/// @@ -88,7 +91,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); _; } @@ -114,11 +117,9 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { constructor( address _orchestratorProxy, - address _masterPoolProxyAddress, address _childProxy, address _link, address _ccipRouter, - uint64 _destinationChainSelector, address _usdc, address _owner ) CCIPReceiver(_ccipRouter) { @@ -126,8 +127,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,38 +135,44 @@ contract ConceroChildPool is CCIPReceiver, ChildStorage { //////////////////////// /** - * @notice Function to Distribute Liquidity across Concero Pools - * @param _liquidityProviderAddress The liquidity provider that requested Withdraw - * @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. + * @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(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(i_parentPoolProxyAddress), - 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); + 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_poolChainSelectors.length; + if (numberOfPools < ALLOWED) revert ConceroChildPool_ThereIsNoPoolToDistribute(); - emit ConceroChildPool_MessageSent(messageId, i_parentPoolChainSelector, i_parentPoolProxyAddress, address(i_linkToken), fees); + uint256 amountToSentToEachPool = (i_USDC.balanceOf(address(this)) / numberOfPools) - 1; - messageId = IRouterClient(i_ccipRouter).ccipSend(i_parentPoolChainSelector, 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_poolChainSelectors[i], address(0), amountToSentToEachPool); + unchecked { + ++i; + } + } } /** @@ -202,13 +207,49 @@ 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; 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. + */ + function setPools(uint64 _chainSelector, address _pool) external payable isProxy onlyOwner { + if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroChildPool_InvalidAddress(); + + s_poolChainSelectors.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 removePools(uint64 _chainSelector) external payable isProxy onlyOwner { + + 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 { + ++i; + } + } + + emit ConceroChildPool_ChainAndAddressRemoved(_chainSelector); + } + //////////////// /// INTERNAL /// //////////////// @@ -246,6 +287,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_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(); + + 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/// /////////////////////////// @@ -254,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 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/ParentPool.sol b/packages/hardhat/contracts/ConceroParentPool.sol similarity index 59% rename from packages/hardhat/contracts/ParentPool.sol rename to packages/hardhat/contracts/ConceroParentPool.sol index 3402df272..6db4c4fe4 100644 --- a/packages/hardhat/contracts/ParentPool.sol +++ b/packages/hardhat/contracts/ConceroParentPool.sol @@ -11,9 +11,9 @@ 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 {ParentPoolStorage} from "contracts/Libraries/ParentPoolStorage.sol"; import {IOrchestrator} from "./Interfaces/IOrchestrator.sol"; import {Orchestrator} from "./Orchestrator.sol"; @@ -21,31 +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 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(); -contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { +//todo: ConceroParentPool +contract ConceroParentPool is CCIPReceiver, FunctionsClient, ParentPoolStorage { /////////////////////// ///TYPE DECLARATIONS/// /////////////////////// @@ -83,14 +86,14 @@ 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; ///@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,35 +103,37 @@ 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 //////////////////////// //////////////////////////////////////////////////////// ///@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, 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); + 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 ConceroParentPool_RedistributionStarted(bytes32 requestId); ///@notice event emitted when the MasterPool Cap is increased - event ParentPool_MasterPoolCapUpdated(uint256 _newCap); + event ConceroParentPool_MasterPoolCapUpdated(uint256 _newCap); /////////////// ///MODIFIERS/// @@ -139,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); _; } @@ -147,12 +152,20 @@ 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(); + _; + } + + /** + * @notice modifier to check if the caller is the an approved messenger + */ + modifier onlyMessenger() { + if (isMessenger(msg.sender) == false) revert ConceroParentPool_NotMessenger(msg.sender); _; } @@ -197,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; @@ -211,37 +224,37 @@ 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; + uint256 numberOfPools = s_poolChainSelectors.length; - if (numberOfPools < 1) revert ParentPool_ThereIsNoPoolToDistribute(); + 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); 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(), - amount: _usdcAmount + amount: depositMinusFee }); - 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)); + i_USDC.safeTransfer(i_infraProxy, _convertToUSDCTokenDecimals(depositFee)); - _ccipSend(numberOfPools, amountToDistribute); + _distributeLiquidity(amountToDistribute); } /** @@ -249,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); @@ -258,15 +271,15 @@ 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(), amount: _lpAmount }); - emit ParentPool_WithdrawRequest(msg.sender, i_USDC, block.timestamp + WITHDRAW_DEADLINE); + emit ConceroParentPool_WithdrawRequest(msg.sender, i_USDC, block.timestamp + WITHDRAW_DEADLINE); } /** @@ -276,25 +289,35 @@ 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(); + 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; 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 ParentPool_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); + } + + /** + * @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 ConceroParentPool_InvalidAddress(); + _ccipSend(_chainSelector, _amountToSend); } /////////////////////// @@ -309,72 +332,114 @@ 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 { - if (_contractAddress == address(0)) revert ParentPool_InvalidAddress(); + function setConceroContractSender(uint64 _chainSelector, address _contractAddress, uint256 _isAllowed) external payable isProxy onlyOwner { + if (_contractAddress == address(0)) revert ConceroParentPool_InvalidAddress(); s_contractsToReceiveFrom[_chainSelector][_contractAddress] = _isAllowed; - 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) external payable onlyOwner { - if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ParentPool_InvalidAddress(); - s_poolsToDistribute.push(IParentPool.Pools({chainSelector: _chainSelector, poolAddress: _pool})); - - s_poolToSendTo[_chainSelector] = _pool; - - emit ParentPool_PoolReceiverUpdated(_chainSelector, _pool); + emit ConceroParentPool_ConceroSendersUpdated(_chainSelector, _contractAddress, _isAllowed); } /** * @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); + emit ConceroParentPool_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; } + /** + * @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 setPools(uint64 _chainSelector, address _pool, bool isRebalance) external payable isProxy onlyOwner { + if (s_poolToSendTo[_chainSelector] == _pool || _pool == address(0)) revert ConceroParentPool_InvalidAddress(); + + s_poolChainSelectors.push(_chainSelector); + s_poolToSendTo[_chainSelector] = _pool; + + emit ConceroParentPool_PoolReceiverUpdated(_chainSelector, _pool); + + if (isRebalance == true) { + //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); + args[1] = abi.encodePacked(s_ethersHashSum); + args[2] = abi.encodePacked(_chainSelector); + 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)*/; + + // s_requests[requestId] = CLFRebalance({ + // }); + + emit ConceroParentPool_RedistributionStarted(requestId); + } + } + /** * @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 { - for (uint256 i; i < s_poolsToDistribute.length; ) { - if (s_poolsToDistribute[i].chainSelector == _chainSelector) { - s_poolsToDistribute[i] = s_poolsToDistribute[s_poolsToDistribute.length - 1]; - s_poolsToDistribute.pop(); + function removePools(uint64 _chainSelector) external payable isProxy onlyOwner { + address removedPool; + for (uint256 i; i < s_poolChainSelectors.length; ) { + if (s_poolChainSelectors[i] == _chainSelector) { + removedPool = s_poolToSendTo[_chainSelector]; + s_poolChainSelectors[i] = s_poolChainSelectors[s_poolChainSelectors.length - 1]; + s_poolChainSelectors.pop(); delete s_poolToSendTo[_chainSelector]; } unchecked { ++i; } } - emit ParentPool_ChainAndAddressRemoved(_chainSelector); + + emit ConceroParentPool_ChainAndAddressRemoved(_chainSelector); + + //send through functions? + // 1. Trigger the liquidatePool functions to transfer money equally to other pools + + 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); + + //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({ + // }); + + emit ConceroParentPool_RedistributionStarted(requestId); } //////////////// @@ -406,7 +471,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 @@ -416,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)), @@ -426,39 +491,46 @@ 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 _amountToDistribute amount of USDC should be distributed to the pools. */ - function _ccipSend(uint256 _numberOfPools, uint256 _amountToDistribute) internal returns (bytes32 messageId) { - for (uint256 i; i < _numberOfPools; ) { - IParentPool.Pools memory pool = s_poolsToDistribute[i]; + function _distributeLiquidity(uint256 _amountToDistribute) internal { + uint256 numberOfPools = s_poolChainSelectors.length; + for (uint256 i; i < numberOfPools; ) { + _ccipSend(s_poolChainSelectors[i], _amountToDistribute); - Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), _amountToDistribute, pool.poolAddress); + unchecked { + ++i; + } + } + } - uint256 fees = IRouterClient(i_ccipRouter).getFee(pool.chainSelector, evm2AnyMessage); + /** + * @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, uint256 _amountToDistribute) internal returns (bytes32 messageId) { + Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(_chainSelector, address(i_USDC), _amountToDistribute); - if (fees > i_linkToken.balanceOf(address(this))) revert ParentPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); + uint256 fees = IRouterClient(i_ccipRouter).getFee(_chainSelector, evm2AnyMessage); - i_USDC.approve(i_ccipRouter, _amountToDistribute); - i_linkToken.approve(i_ccipRouter, fees); + if (fees > i_linkToken.balanceOf(address(this))) revert ConceroParentPool_NotEnoughLinkBalance(i_linkToken.balanceOf(address(this)), fees); - messageId = IRouterClient(i_ccipRouter).ccipSend(pool.chainSelector, evm2AnyMessage); + i_USDC.approve(i_ccipRouter, _amountToDistribute); + i_linkToken.approve(i_ccipRouter, fees); - emit ParentPool_MessageSent(messageId, pool.chainSelector, pool.poolAddress, address(i_linkToken), fees); + messageId = IRouterClient(i_ccipRouter).ccipSend(_chainSelector, evm2AnyMessage); - unchecked { - ++i; - } - } + emit ConceroParentPool_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})), @@ -488,7 +560,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 +570,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 /// /////////////// @@ -552,7 +620,7 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { * @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) @@ -561,7 +629,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 @@ -575,76 +643,74 @@ contract ParentPool is CCIPReceiver, FunctionsClient, ParentStorage { s_pendingWithdrawRequests[_liquidityProvider] = request; i_automation.addPendingWithdrawal(_liquidityProvider); - emit ParentPool_RequestUpdated(_liquidityProvider); - } - - // function _calculateDepositTransactionFee(uint256 _amountToDistribute) internal view returns(uint256 _totalUSDCCost){ - // uint256 numberOfPools = s_poolsToDistribute.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; ){ - // IParentPool.Pools memory pool = s_poolsToDistribute[i]; - // Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(address(i_USDC), (_amountToDistribute / (numberOfPools+1)), pool.poolAddress); - - // //Link cost for all transactions - // costOfLinkForLiquidityDistribution += IRouterClient(i_ccipRouter).getFee(pool.chainSelector, 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_poolsToDistribute.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; ){ - // IParentPool.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; - // 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; - // } + 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(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/// @@ -667,6 +733,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; } @@ -675,8 +745,25 @@ 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; } } diff --git a/packages/hardhat/contracts/Constants.sol b/packages/hardhat/contracts/Constants.sol index 2aa8f993a..66df6a132 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; diff --git a/packages/hardhat/contracts/DexSwap.sol b/packages/hardhat/contracts/DexSwap.sol index 02c1769a4..2c4d94215 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//////////////////////////// ///////////////////////////////////////////////////////////////// @@ -233,7 +220,7 @@ contract DexSwap is IDexSwap, Storage { recipient: _recipient, deadline: deadline, amountIn: _swapData.fromAmount, - amountOutMinimum: _swapData.toAmountMin, + amountOutMinimum: _swapData.toAmountMin, sqrtPriceLimitX96: sqrtPriceLimitX96 }); 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 83% rename from packages/hardhat/contracts/Interfaces/IParentPool.sol rename to packages/hardhat/contracts/Interfaces/IPool.sol index 08440c87b..36aa12ea8 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/// /////////////////////// @@ -15,12 +15,6 @@ interface IParentPool { uint256 deadline; } - ///@notice `ccipSend` to distribute liquidity - struct Pools { - uint64 chainSelector; - address poolAddress; - } - ///@notice Struct to track Functions Requests Type enum RequestType { GetTotalUSDC, //Deposits @@ -48,11 +42,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/ChildStorage.sol b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol similarity index 64% rename from packages/hardhat/contracts/Libraries/ChildStorage.sol rename to packages/hardhat/contracts/Libraries/ChildPoolStorage.sol index ddb8aeb63..d144573f5 100644 --- a/packages/hardhat/contracts/Libraries/ChildStorage.sol +++ b/packages/hardhat/contracts/Libraries/ChildPoolStorage.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.20; -contract ChildStorage { +contract ChildPoolStorage { ///////////////////// ///STATE VARIABLES/// ///////////////////// @@ -13,6 +13,11 @@ contract ChildStorage { ///////////// ///STORAGE/// ///////////// + ///@notice array of chain IDS of Pools to receive Liquidity through `ccipSend` function + uint64[] s_poolChainSelectors; + ///@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/ParentPoolStorage.sol similarity index 74% rename from packages/hardhat/contracts/Libraries/ParentStorage.sol rename to packages/hardhat/contracts/Libraries/ParentPoolStorage.sol index 055c18180..c4f8dcec6 100644 --- a/packages/hardhat/contracts/Libraries/ParentStorage.sol +++ b/packages/hardhat/contracts/Libraries/ParentPoolStorage.sol @@ -1,19 +1,20 @@ //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 { +// todo: ParentPoolStorage +contract ParentPoolStorage { ///////////////////// ///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 @@ -29,14 +30,14 @@ contract ParentStorage { ///STORAGE/// ///////////// ///@notice array of Pools to receive Liquidity through `ccipSend` function - IParentPool.Pools[] s_poolsToDistribute; + uint64[] s_poolChainSelectors; - ///@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; ///@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..1bf53f6d4 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. @@ -50,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/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..3c55187d5 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; @@ -86,6 +98,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 +127,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, @@ -141,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; @@ -212,6 +207,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(); @@ -226,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; @@ -237,11 +246,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); @@ -264,9 +280,33 @@ 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/// /////////////////////////// + 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/Proxy/ChildPoolProxy.sol b/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol index 72bfab928..dc447855c 100644 --- a/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol +++ b/packages/hardhat/contracts/Proxy/ChildPoolProxy.sol @@ -6,9 +6,8 @@ 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"; +import {ChildPoolStorage} from "../Libraries/ChildPoolStorage.sol"; /** * @dev Interface for {TransparentUpgradeableProxy}. In order to implement transparency, {TransparentUpgradeableProxy} @@ -61,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/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..39a22ba48 100644 --- a/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol +++ b/packages/hardhat/contracts/Proxy/ParentPoolProxy.sol @@ -6,9 +6,8 @@ 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"; +import {ParentPoolStorage} from "../Libraries/ParentPoolStorage.sol"; /** * @dev Interface for {TransparentUpgradeableProxy}. In order to implement transparency, {TransparentUpgradeableProxy} @@ -61,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/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); } diff --git a/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts b/packages/hardhat/tasks/concero/deployPool/setParentPoolVariables.ts index 8ecdfce92..0ec501022 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, @@ -300,13 +300,13 @@ async function removePoolsFromListOfSenders(chain: CNetwork, abi, chainSelectors }); 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); @@ -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"); } 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;