From 5b5d4299e13efbcc43d21c69dc2ac4e529a027be Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:48:14 +0200 Subject: [PATCH 01/51] fix: add RECEIVER_ADDRESS_EQUAL_TO_PROCESSOR_ADDRESS() error --- src/libraries/Error.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libraries/Error.sol b/src/libraries/Error.sol index 4c90f51fb..40b63c3a2 100644 --- a/src/libraries/Error.sol +++ b/src/libraries/Error.sol @@ -164,6 +164,9 @@ library Error { /// @dev thrown if receiver address is not set error RECEIVER_ADDRESS_NOT_SET(); + /// @dev thrown if receiver address is equal to procssor address + error RECEIVER_ADDRESS_EQUAL_TO_PROCESSOR_ADDRESS(); + /// SUPERFORM FACTORY INPUT VALIDATION ERRORS /// --------------------------------------------------------- From 11cc0dab5c3b0561f9ff4aa1cc7d8c9634dfef79 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:57:09 +0200 Subject: [PATCH 02/51] fix: move RECEIVER_ADDRESS_EQUAL_TO_PROCESSOR_ADDRESS() error to ISuperfromRouterPlusAsync.sol --- src/interfaces/ISuperformRouterPlusAsync.sol | 3 +++ src/libraries/Error.sol | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 94842aac4..211472be4 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -15,6 +15,9 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when a non-processor attempts to call a processor-only function error NOT_ROUTER_PLUS_PROCESSOR(); + /// @notice thrown if refund receiver address is equal to processor address + error RECEIVER_ADDRESS_EQUAL_TO_PROCESSOR_ADDRESS(); + /// @notice thrown if the caller is not router plus error NOT_ROUTER_PLUS(); diff --git a/src/libraries/Error.sol b/src/libraries/Error.sol index 40b63c3a2..4c90f51fb 100644 --- a/src/libraries/Error.sol +++ b/src/libraries/Error.sol @@ -164,9 +164,6 @@ library Error { /// @dev thrown if receiver address is not set error RECEIVER_ADDRESS_NOT_SET(); - /// @dev thrown if receiver address is equal to procssor address - error RECEIVER_ADDRESS_EQUAL_TO_PROCESSOR_ADDRESS(); - /// SUPERFORM FACTORY INPUT VALIDATION ERRORS /// --------------------------------------------------------- From f380c7a91a1456690b311d82fac55cda1f629904 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:59:56 +0200 Subject: [PATCH 03/51] chore: rename IS_ROUTER_PLUS_PROCESSOR() error --- src/interfaces/ISuperformRouterPlusAsync.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 211472be4..7b3200be6 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -15,8 +15,8 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when a non-processor attempts to call a processor-only function error NOT_ROUTER_PLUS_PROCESSOR(); - /// @notice thrown if refund receiver address is equal to processor address - error RECEIVER_ADDRESS_EQUAL_TO_PROCESSOR_ADDRESS(); + /// @notice thrown when a processor attempts to call finalizeRefund function + error IS_ROUTER_PLUS_PROCESSOR(); /// @notice thrown if the caller is not router plus error NOT_ROUTER_PLUS(); From 00151dab15f1494a33517fe6dfde6f4f13ca1ae6 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:02:12 +0200 Subject: [PATCH 04/51] chore: rm unused error --- src/interfaces/ISuperformRouterPlusAsync.sol | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 7b3200be6..94842aac4 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -15,9 +15,6 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when a non-processor attempts to call a processor-only function error NOT_ROUTER_PLUS_PROCESSOR(); - /// @notice thrown when a processor attempts to call finalizeRefund function - error IS_ROUTER_PLUS_PROCESSOR(); - /// @notice thrown if the caller is not router plus error NOT_ROUTER_PLUS(); From 71d5769e4fac5bdd820f43a9423dda3f5a8ca1e7 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:13:15 +0200 Subject: [PATCH 05/51] add NOT_CORE_STATE_REGISTRY_RESCUER() error --- src/interfaces/ISuperformRouterPlusAsync.sol | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 94842aac4..5dcba1a51 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -18,6 +18,9 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown if the caller is not router plus error NOT_ROUTER_PLUS(); + /// @notice thrown if the caller is not core state registry rescuer + error NOT_CORE_STATE_REGISTRY_RESCUER(); + /// @notice thrown if the rebalance to update is invalid error COMPLETE_REBALANCE_INVALID_TX_DATA_UPDATE(); @@ -168,6 +171,15 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { payable returns (bool rebalanceSuccessful); + /// @notice allows the user to request a refund for the rebalance + /// @param requestedAmount_ the amount to be refunded + function requestRefund(uint256 requestedAmount_) external; + + /// @dev only callable by core state registry rescuer + /// @notice approves a refund for the rebalance and sends funds to the receiver + /// @param routerplusPayloadId_ the router plus payload id + function approveRefund(uint256 routerplusPayloadId_) external; + /// @notice allows the receiver / disputer to protect against malicious processors /// @param finalPayloadId_ is the unique identifier of the refund function disputeRefund(uint256 finalPayloadId_) external; From 5f472a08800fafe8b7aab19039a07582ccc44fcb Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:26:17 +0200 Subject: [PATCH 06/51] add REFUND_AMOUNT_EXCEEDS_RECEIVED_AMOUNT() error --- src/interfaces/ISuperformRouterPlusAsync.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 5dcba1a51..10086087e 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -53,6 +53,9 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when the refund payload is invalid error INVALID_REFUND_DATA(); + /// @notice thrown when requestedrefund amount exceeds received amount + error REFUND_AMOUNT_EXCEEDS_RECEIVED_AMOUNT(); + /// @notice thrown when refund is already proposed error REFUND_ALREADY_PROPOSED(); From 5fb5af1217d7422ba886413776e627bd06ac3e3f Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:26:56 +0200 Subject: [PATCH 07/51] chore: rename REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT() error --- src/interfaces/ISuperformRouterPlusAsync.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 10086087e..d5faaeeb5 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -54,7 +54,7 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { error INVALID_REFUND_DATA(); /// @notice thrown when requestedrefund amount exceeds received amount - error REFUND_AMOUNT_EXCEEDS_RECEIVED_AMOUNT(); + error REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); /// @notice thrown when refund is already proposed error REFUND_ALREADY_PROPOSED(); From c1c2f331036497483c3f679ff3f3f85dfe57aec2 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:29:28 +0200 Subject: [PATCH 08/51] feat: add requestRefund() function --- src/router-plus/SuperformRouterPlusAsync.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 550c1cab2..179563975 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -35,6 +35,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou mapping(uint256 routerPlusPayloadId => Refund) public refunds; mapping(uint256 routerPlusPayloadId => bool processed) public processedRebalancePayload; + ////////////////////////////////////////////////////////////// // MODIFIERS // ////////////////////////////////////////////////////////////// @@ -414,6 +415,24 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou return true; } + /// @inheritdoc ISuperformRouterPlusAsync + function requestRefund(uint256 requestedAmount_, uint256 routerPlusPayloadId_) external { + Refund memory r = refunds[routerPlusPayloadId_]; + + if (msg.sender != r.receiver) revert INVALID_PROPOSER(); + if (requestedAmount_ == 0) revert Error.ZERO_INPUT_VALUE(); + if (r.interimToken == address(0)) revert INVALID_REFUND_DATA(); + + if (r.proposedTime != 0) revert REFUND_ALREADY_PROPOSED(); + r.proposedTime = block.timestamp; + r.amount = requestedAmount_; + + emit RefundInitiated( + routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_ + ); + } + + /// @inheritdoc ISuperformRouterPlusAsync function disputeRefund(uint256 routerPlusPayloadId_) external override { Refund storage r = refunds[routerPlusPayloadId_]; From 4879f8e145f8c4093c525398978f8c92727ab6e8 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:30:38 +0200 Subject: [PATCH 09/51] fix: update requestRefund() params --- src/interfaces/ISuperformRouterPlusAsync.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index d5faaeeb5..3cfc2c896 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -176,7 +176,7 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice allows the user to request a refund for the rebalance /// @param requestedAmount_ the amount to be refunded - function requestRefund(uint256 requestedAmount_) external; + function requestRefund(uint256 requestedAmount_, uint256 routerplusPayloadId_) external; /// @dev only callable by core state registry rescuer /// @notice approves a refund for the rebalance and sends funds to the receiver From 53ac16428505d3a85bc7d32c40e2b97fa5fca2a4 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:31:31 +0200 Subject: [PATCH 10/51] chore: add onlyCoreStateRegistryRescuer() modifier --- src/router-plus/SuperformRouterPlusAsync.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 179563975..f28716832 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -54,6 +54,13 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou _; } + modifier onlyCoreStateRegistryRescuer() { + if (!_hasRole(keccak256("CORE_STATE_REGISTRY_RESCUER_ROLE"), msg.sender)) { + revert NOT_CORE_STATE_REGISTRY_RESCUER(); + } + _; + } + ////////////////////////////////////////////////////////////// // CONSTRUCTOR // ////////////////////////////////////////////////////////////// From a0a746e3a0ae8d5334384f389b7f2047367ea844 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:32:00 +0200 Subject: [PATCH 11/51] feat: add approveRefund() --- src/router-plus/SuperformRouterPlusAsync.sol | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index f28716832..5182f5934 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -439,6 +439,22 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou ); } + /// @inheritdoc ISuperformRouterPlusAsync + function approveRefund(uint256 routerPlusPayloadId_) external onlyCoreStateRegistryRescuer { + Refund memory r = refunds[routerPlusPayloadId_]; + + XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; + + if (data.expectedAmountInterimAsset < r.amount) revert REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); + + /// @dev deleting to prevent re-entrancy + delete refunds[routerPlusPayloadId_]; + + IERC20(r.interimToken).safeTransfer(r.receiver, r.amount); + + emit RefundCompleted(routerPlusPayloadId_, msg.sender); + } + /// @inheritdoc ISuperformRouterPlusAsync function disputeRefund(uint256 routerPlusPayloadId_) external override { From a79275c37fed5e90fa812611f36a2e9e3394a7ff Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:34:45 +0200 Subject: [PATCH 12/51] refactor: rm old refund functions --- src/interfaces/ISuperformRouterPlusAsync.sol | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 3cfc2c896..adcb507ac 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -182,17 +182,4 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice approves a refund for the rebalance and sends funds to the receiver /// @param routerplusPayloadId_ the router plus payload id function approveRefund(uint256 routerplusPayloadId_) external; - - /// @notice allows the receiver / disputer to protect against malicious processors - /// @param finalPayloadId_ is the unique identifier of the refund - function disputeRefund(uint256 finalPayloadId_) external; - - /// @notice allows the rescuer to propose a new refund amount after a successful dispute - /// @param finalPayloadId_ is the unique identifier of the refund - /// @param refundAmount_ is the new refund amount proposed - function proposeRefund(uint256 finalPayloadId_, uint256 refundAmount_) external; - - /// @notice allows the user to claim their refund post the dispute period - /// @param finalPayloadId_ is the unique identifier of the refund - function finalizeRefund(uint256 finalPayloadId_) external; } From 9924cab8771482d39b1f11f1f1ed856705c6a32b Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:35:16 +0200 Subject: [PATCH 13/51] refactor: rm old refund functions --- src/router-plus/SuperformRouterPlusAsync.sol | 47 -------------------- 1 file changed, 47 deletions(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 5182f5934..e3606ba0a 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -455,53 +455,6 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou emit RefundCompleted(routerPlusPayloadId_, msg.sender); } - - /// @inheritdoc ISuperformRouterPlusAsync - function disputeRefund(uint256 routerPlusPayloadId_) external override { - Refund storage r = refunds[routerPlusPayloadId_]; - - if (!(msg.sender == r.receiver || _hasRole(keccak256("CORE_STATE_REGISTRY_DISPUTER_ROLE"), msg.sender))) { - revert Error.NOT_VALID_DISPUTER(); - } - - if (r.proposedTime == 0 || block.timestamp > r.proposedTime + _getDelay()) revert Error.DISPUTE_TIME_ELAPSED(); - - /// @dev just can reset the last proposed time, since amounts should be updated again to - /// pass the proposedTime zero check in finalize - r.proposedTime = 0; - - emit RefundDisputed(routerPlusPayloadId_, msg.sender); - } - - /// @inheritdoc ISuperformRouterPlusAsync - function proposeRefund(uint256 routerPlusPayloadId_, uint256 refundAmount_) external { - if (!_hasRole(keccak256("CORE_STATE_REGISTRY_RESCUER_ROLE"), msg.sender)) revert INVALID_PROPOSER(); - - Refund storage r = refunds[routerPlusPayloadId_]; - - if (r.interimToken == address(0) || r.receiver == address(0)) revert INVALID_REFUND_DATA(); - if (r.proposedTime != 0) revert REFUND_ALREADY_PROPOSED(); - - r.proposedTime = block.timestamp; - r.amount = refundAmount_; - - emit NewRefundAmountProposed(routerPlusPayloadId_, refundAmount_); - } - - /// @inheritdoc ISuperformRouterPlusAsync - function finalizeRefund(uint256 routerPlusPayloadId_) external { - Refund memory r = refunds[routerPlusPayloadId_]; - - if (r.proposedTime == 0 || block.timestamp <= r.proposedTime + _getDelay()) revert IN_DISPUTE_PHASE(); - - /// @dev deleting to prevent re-entrancy - delete refunds[routerPlusPayloadId_]; - - IERC20(r.interimToken).safeTransfer(r.receiver, r.amount); - - emit RefundCompleted(routerPlusPayloadId_, msg.sender); - } - ////////////////////////////////////////////////////////////// // INTERNAL FUNCTIONS // ////////////////////////////////////////////////////////////// From e42992c8a0160fde3e086448c99e1657372616e3 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:35:47 +0200 Subject: [PATCH 14/51] refactor: rm _getDelay() --- src/router-plus/SuperformRouterPlusAsync.sol | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index e3606ba0a..32608ecec 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -459,15 +459,6 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou // INTERNAL FUNCTIONS // ////////////////////////////////////////////////////////////// - /// @dev returns the current dispute delay - function _getDelay() internal view returns (uint256) { - uint256 delay = superRegistry.delay(); - if (delay == 0) { - revert Error.DELAY_NOT_SET(); - } - return delay; - } - function _updateSuperformData( MultiVaultSFData memory sfData, LiqRequest[] memory liqRequests, From 7f790d31833f579c9aadc88d46a27e9a11bc550c Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:36:25 +0200 Subject: [PATCH 15/51] refactor: rm refund proposal time checks --- src/router-plus/SuperformRouterPlusAsync.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 32608ecec..4839ae6ec 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -430,8 +430,6 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou if (requestedAmount_ == 0) revert Error.ZERO_INPUT_VALUE(); if (r.interimToken == address(0)) revert INVALID_REFUND_DATA(); - if (r.proposedTime != 0) revert REFUND_ALREADY_PROPOSED(); - r.proposedTime = block.timestamp; r.amount = requestedAmount_; emit RefundInitiated( From 26d0e22427e1993824dcea9c6dcf920b46431344 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:39:27 +0200 Subject: [PATCH 16/51] refactor: rm tests for old refund mechanism --- .../router-plus/SuperformRouterPlus.t.sol | 51 +------------------ 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 35dcb6a50..722d6f567 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1698,56 +1698,7 @@ contract SuperformRouterPlusTest is ProtocolActions { SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); vm.stopPrank(); - vm.expectRevert(Error.NOT_VALID_DISPUTER.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).disputeRefund(1); - - vm.startPrank(deployer); - vm.mockCall( - address(getContract(SOURCE_CHAIN, "SuperRegistry")), - abi.encodeWithSelector(ISuperRegistry.delay.selector), - abi.encode(0) - ); - vm.expectRevert(Error.DELAY_NOT_SET.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).disputeRefund(1); - vm.clearMockedCalls(); - - vm.warp(block.timestamp + 100 days); - vm.expectRevert(Error.DISPUTE_TIME_ELAPSED.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).disputeRefund(1); - - vm.warp(block.timestamp - 100 days); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).disputeRefund(1); - - vm.expectRevert(Error.DISPUTE_TIME_ELAPSED.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).disputeRefund(1); - vm.stopPrank(); - - vm.expectRevert(ISuperformRouterPlusAsync.INVALID_PROPOSER.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).proposeRefund(1, completeArgs.amountReceivedInterimAsset); - - vm.startPrank(deployer); - vm.expectRevert(ISuperformRouterPlusAsync.INVALID_REFUND_DATA.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).proposeRefund(2, completeArgs.amountReceivedInterimAsset); - - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).proposeRefund(1, completeArgs.amountReceivedInterimAsset); - - vm.expectRevert(ISuperformRouterPlusAsync.REFUND_ALREADY_PROPOSED.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).proposeRefund(1, completeArgs.amountReceivedInterimAsset); - - vm.expectRevert(ISuperformRouterPlusAsync.IN_DISPUTE_PHASE.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).finalizeRefund(1); - - (, address refundToken,,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); - uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); - - vm.warp(block.timestamp + 100 days); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).finalizeRefund(1); - uint256 balanceAfter = MockERC20(refundToken).balanceOf(deployer); - - assertGt(balanceAfter, balanceBefore); - - vm.expectRevert(ISuperformRouterPlusAsync.IN_DISPUTE_PHASE.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).finalizeRefund(1); + // ToDo: test refund flow } function test_crossChainRebalance_negativeSlippage() public { From 3506d869624383182280f8b9d7edcab44ef09688 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:43:09 +0200 Subject: [PATCH 17/51] chore: rm unused errors --- src/interfaces/ISuperformRouterPlusAsync.sol | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index adcb507ac..ea2a18db4 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -56,12 +56,6 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when requestedrefund amount exceeds received amount error REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); - /// @notice thrown when refund is already proposed - error REFUND_ALREADY_PROPOSED(); - - /// @notice thrown if the refund is still in dispute phase - error IN_DISPUTE_PHASE(); - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// From 2ec17535831d216086471e9fc0dcaf298a49b5cf Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:58:39 +0200 Subject: [PATCH 18/51] add REFUND_ALREADY_APPROVED() error --- src/interfaces/ISuperformRouterPlusAsync.sol | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index ea2a18db4..4d989466a 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -47,8 +47,8 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown to avoid processing the same rebalance payload twice error REBALANCE_ALREADY_PROCESSED(); - /// @notice thrown when the refund proposer is invalid - error INVALID_PROPOSER(); + /// @notice thrown when the refund requester is not the payload receiver + error INVALID_REQUESTER(); /// @notice thrown when the refund payload is invalid error INVALID_REFUND_DATA(); @@ -56,6 +56,9 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when requestedrefund amount exceeds received amount error REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); + /// @notice thrown when the refund payload is already approved + error REFUND_ALREADY_APPROVED(); + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// From b9cea458b34605faf854fcb11eb371faa6df3f82 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:59:12 +0200 Subject: [PATCH 19/51] fix: add checks for duplicate approvals --- src/router-plus/SuperformRouterPlusAsync.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 4839ae6ec..63b110330 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -36,6 +36,8 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou mapping(uint256 routerPlusPayloadId => Refund) public refunds; mapping(uint256 routerPlusPayloadId => bool processed) public processedRebalancePayload; + mapping(uint256 routerPlusPayloadId => bool approvedRefund) public approvedRefund; + ////////////////////////////////////////////////////////////// // MODIFIERS // ////////////////////////////////////////////////////////////// @@ -426,7 +428,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou function requestRefund(uint256 requestedAmount_, uint256 routerPlusPayloadId_) external { Refund memory r = refunds[routerPlusPayloadId_]; - if (msg.sender != r.receiver) revert INVALID_PROPOSER(); + if (msg.sender != r.receiver) revert INVALID_REQUESTER(); if (requestedAmount_ == 0) revert Error.ZERO_INPUT_VALUE(); if (r.interimToken == address(0)) revert INVALID_REFUND_DATA(); @@ -439,12 +441,16 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou /// @inheritdoc ISuperformRouterPlusAsync function approveRefund(uint256 routerPlusPayloadId_) external onlyCoreStateRegistryRescuer { + if (approvedRefund[routerPlusPayloadId_]) revert REFUND_ALREADY_APPROVED(); + Refund memory r = refunds[routerPlusPayloadId_]; XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; if (data.expectedAmountInterimAsset < r.amount) revert REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); + approvedRefund[routerPlusPayloadId_] = true; + /// @dev deleting to prevent re-entrancy delete refunds[routerPlusPayloadId_]; From a49417f96166c530bdcc91eb2181e0c174d4e5a2 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:59:37 +0200 Subject: [PATCH 20/51] chore: add test case for duplicate approvals --- .../router-plus/SuperformRouterPlus.t.sol | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 722d6f567..59a494047 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1698,7 +1698,52 @@ contract SuperformRouterPlusTest is ProtocolActions { SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); vm.stopPrank(); - // ToDo: test refund flow + // Step 5: Request refund + + /// @dev testing invalid requester + vm.startPrank(address(222)); + vm.expectRevert(ISuperformRouterPlusAsync.INVALID_REQUESTER.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(completeArgs.amountReceivedInterimAsset, 1); + vm.stopPrank(); + + /// @dev testing zero input value + vm.startPrank(deployer); + vm.expectRevert(Error.ZERO_INPUT_VALUE.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(0, 1); + + /// @dev testing valid refund request + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(completeArgs.amountReceivedInterimAsset, 1); + vm.stopPrank(); + + // Step 6: Approve refund + + /// @dev testing invalid approver + vm.startPrank(address(1234)); + vm.expectRevert(); + SuperformRouterPlusAsync(address(1234)).approveRefund(1); + vm.stopPrank(); + + /// @dev testing refund amount exceeds expected amount + vm.startPrank(deployer); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(100, 1); + vm.expectRevert(ISuperformRouterPlusAsync.REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); + vm.stopPrank(); + + (, address refundToken,,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); + + /// @dev testing valid refund approval + vm.startPrank(deployer); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); + vm.stopPrank(); + + uint256 balanceAfter = MockERC20(refundToken).balanceOf(deployer); + assertGt(balanceAfter, balanceBefore); + + /// @dev testing refund already approved + vm.expectRevert(ISuperformRouterPlusAsync.REFUND_ALREADY_APPROVED.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); } function test_crossChainRebalance_negativeSlippage() public { From 094e8d8b83f8499b7ec29d00b170be1bad54dcd1 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:03:36 +0200 Subject: [PATCH 21/51] chore: formatting --- .../forge-scripts/safe/lib/DelegatePrank.sol | 39 ++++++++++--------- src/BaseForm.sol | 3 +- .../extensions/AsyncStateRegistry.sol | 4 +- src/crosschain-data/utils/QuorumManager.sol | 1 - .../debridge/libraries/DeBridgeError.sol | 2 +- .../socket/SocketOneInchValidator.sol | 1 - src/forms/ERC4626FormImplementation.sol | 4 +- src/forms/interfaces/IERC4626Form.sol | 1 - src/interfaces/IAsyncStateRegistry.sol | 4 +- src/interfaces/IBaseForm.sol | 1 - src/interfaces/IBaseRouter.sol | 1 - .../IBroadcastAmbImplementation.sol | 1 - src/interfaces/ICoreStateRegistry.sol | 12 +++--- src/interfaces/IDstSwapper.sol | 1 - src/interfaces/IEmergencyQueue.sol | 1 - src/interfaces/IPayMaster.sol | 1 - src/interfaces/IQuorumManager.sol | 1 - src/interfaces/ISuperPositions.sol | 3 +- src/interfaces/ISuperRBAC.sol | 1 - src/interfaces/ISuperformFactory.sol | 1 - src/router-plus/SuperformRouterPlusAsync.sol | 6 +-- .../lifi/celer-network/MsgDataTypes.sol | 2 + test/unit/payments/PaymentHelper.t.sol | 1 - test/utils/InvariantProtocolActions.sol | 4 +- 24 files changed, 37 insertions(+), 59 deletions(-) diff --git a/script/forge-scripts/safe/lib/DelegatePrank.sol b/script/forge-scripts/safe/lib/DelegatePrank.sol index 0e4b67557..6df91ee9b 100644 --- a/script/forge-scripts/safe/lib/DelegatePrank.sol +++ b/script/forge-scripts/safe/lib/DelegatePrank.sol @@ -20,27 +20,28 @@ import "forge-std/console.sol"; */ contract DelegatePrank is CommonBase { - Delegator delegator = makeDelegator(); - function makeDelegator() internal returns (Delegator) { - return new Delegator(); - } - - function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { - bytes memory code = from.code; - vm.etch(from,address(delegator).code); - (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall,(to,cd,code))); - } + Delegator delegator = makeDelegator(); + + function makeDelegator() internal returns (Delegator) { + return new Delegator(); + } + + function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { + bytes memory code = from.code; + vm.etch(from, address(delegator).code); + (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall, (to, cd, code))); + } } contract Delegator is CommonBase { - function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { - vm.etch(address(this),code); - assembly ("memory-safe") { - let result := delegatecall(gas(), dest, add(cd,32), mload(cd), 0, 0) - returndatacopy(0, 0, returndatasize()) - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } + function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { + vm.etch(address(this), code); + assembly ("memory-safe") { + let result := delegatecall(gas(), dest, add(cd, 32), mload(cd), 0, 0) + returndatacopy(0, 0, returndatasize()) + switch result + case 0 { revert(0, returndatasize()) } + default { return(0, returndatasize()) } + } } - } } diff --git a/src/BaseForm.sol b/src/BaseForm.sol index 750915233..31551584b 100644 --- a/src/BaseForm.sol +++ b/src/BaseForm.sol @@ -16,7 +16,6 @@ import { IERC165 } from "openzeppelin-contracts/contracts/utils/introspection/IE /// @dev Abstract contract to be inherited by different Form implementations /// @author Zeropoint Labs abstract contract BaseForm is IBaseForm, Initializable, ERC165 { - using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -254,7 +253,7 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { } /// @dev Checks if the Form implementation has the appropriate interface support - /// @param interfaceId_ is the interfaceId to check + /// @param interfaceId_ is the interfaceId to check function supportsInterface(bytes4 interfaceId_) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId_ == type(IBaseForm).interfaceId || super.supportsInterface(interfaceId_); } diff --git a/src/crosschain-data/extensions/AsyncStateRegistry.sol b/src/crosschain-data/extensions/AsyncStateRegistry.sol index 37bc93d53..18afd3ac0 100644 --- a/src/crosschain-data/extensions/AsyncStateRegistry.sol +++ b/src/crosschain-data/extensions/AsyncStateRegistry.sol @@ -361,9 +361,7 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } /// @inheritdoc IAsyncStateRegistry - function getSyncWithdrawTxDataPayload( - uint256 payloadId_ - ) + function getSyncWithdrawTxDataPayload(uint256 payloadId_) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_) diff --git a/src/crosschain-data/utils/QuorumManager.sol b/src/crosschain-data/utils/QuorumManager.sol index 42c596e15..b84e48137 100644 --- a/src/crosschain-data/utils/QuorumManager.sol +++ b/src/crosschain-data/utils/QuorumManager.sol @@ -8,7 +8,6 @@ import { Error } from "src/libraries/Error.sol"; /// @dev Quorum thresholds using in sending proofs from chain to chain /// @author ZeroPoint Labs abstract contract QuorumManager is IQuorumManager { - ////////////////////////////////////////////////////////////// // STATE VARIABLES // ////////////////////////////////////////////////////////////// diff --git a/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol b/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol index 704cf5d06..f5e85b308 100644 --- a/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol +++ b/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol @@ -35,4 +35,4 @@ library DeBridgeError { /// @dev if the swap router is invalid error INVALID_SWAP_ROUTER(); -} \ No newline at end of file +} diff --git a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol index e4b55a2d6..15a042f43 100644 --- a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol +++ b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol @@ -9,7 +9,6 @@ import { ISocketOneInchImpl } from "src/vendor/socket/ISocketOneInchImpl.sol"; /// @dev Asserts Socket same-chain txData is valid /// @author Zeropoint Labs contract SocketOneInchValidator is BridgeValidator { - ////////////////////////////////////////////////////////////// // CONSTRUCTOR // ////////////////////////////////////////////////////////////// diff --git a/src/forms/ERC4626FormImplementation.sol b/src/forms/ERC4626FormImplementation.sol index 0d563a171..1c50775f7 100644 --- a/src/forms/ERC4626FormImplementation.sol +++ b/src/forms/ERC4626FormImplementation.sol @@ -16,7 +16,6 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Has common ERC4626 internal functions that can be re-used by implementations /// @author Zeropoint Labs abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { - using SafeERC20 for IERC20; using SafeERC20 for IERC4626; using DataLib for uint256; @@ -229,7 +228,7 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { /// superform data if ( vars.assetDifference * ENTIRE_SLIPPAGE - < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) + < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) ) { revert Error.DIRECT_DEPOSIT_SWAP_FAILED(); } @@ -271,7 +270,6 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { } function _processDirectWithdraw(InitSingleVaultData memory singleVaultData_) internal returns (uint256 assets) { - DirectWithdrawLocalVars memory vars; /// @dev if there is no txData, on withdraws the receiver is receiverAddress, otherwise it diff --git a/src/forms/interfaces/IERC4626Form.sol b/src/forms/interfaces/IERC4626Form.sol index 14cb791f1..9891d2574 100644 --- a/src/forms/interfaces/IERC4626Form.sol +++ b/src/forms/interfaces/IERC4626Form.sol @@ -7,7 +7,6 @@ import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol" /// @dev Interface for ERC4626Form /// @author Zeropoint Labs interface IERC4626Form is IERC20 { - ////////////////////////////////////////////////////////////// // EXTERNAL VIEW FUNCTIONS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IAsyncStateRegistry.sol b/src/interfaces/IAsyncStateRegistry.sol index c47f56881..cee773fce 100644 --- a/src/interfaces/IAsyncStateRegistry.sol +++ b/src/interfaces/IAsyncStateRegistry.sol @@ -101,9 +101,7 @@ interface IAsyncStateRegistry { /// @notice retrieves the sync withdraw txData payload for a given payload ID /// @param payloadId_ The ID of the payload /// @return syncWithdrawTxDataPayload_ for the specified payload ID - function getSyncWithdrawTxDataPayload( - uint256 payloadId_ - ) + function getSyncWithdrawTxDataPayload(uint256 payloadId_) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_); diff --git a/src/interfaces/IBaseForm.sol b/src/interfaces/IBaseForm.sol index 4a298a947..5b380793c 100644 --- a/src/interfaces/IBaseForm.sol +++ b/src/interfaces/IBaseForm.sol @@ -9,7 +9,6 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Interface for BaseForm /// @author ZeroPoint Labs interface IBaseForm is IERC165 { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IBaseRouter.sol b/src/interfaces/IBaseRouter.sol index 7679081b7..3a651f584 100644 --- a/src/interfaces/IBaseRouter.sol +++ b/src/interfaces/IBaseRouter.sol @@ -7,7 +7,6 @@ import "src/types/DataTypes.sol"; /// @dev Interface for abstract BaseRouter /// @author Zeropoint Labs interface IBaseRouter { - ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IBroadcastAmbImplementation.sol b/src/interfaces/IBroadcastAmbImplementation.sol index 545c045bf..83de6ca83 100644 --- a/src/interfaces/IBroadcastAmbImplementation.sol +++ b/src/interfaces/IBroadcastAmbImplementation.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for AMBs used in Broadcasting /// @author ZeroPoint Labs interface IBroadcastAmbImplementation { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/ICoreStateRegistry.sol b/src/interfaces/ICoreStateRegistry.sol index 953130499..a9775e171 100644 --- a/src/interfaces/ICoreStateRegistry.sol +++ b/src/interfaces/ICoreStateRegistry.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for CoreStateRegistry /// @author ZeroPoint Labs interface ICoreStateRegistry { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -34,10 +33,7 @@ interface ICoreStateRegistry { /// @dev is emitted when a rescue is proposed for failed deposits in a payload event RescueProposed( - uint256 indexed payloadId, - uint256[] superformIds, - uint256[] proposedAmount, - uint256 proposedTime + uint256 indexed payloadId, uint256[] superformIds, uint256[] proposedAmount, uint256 proposedTime ); /// @dev is emitted when an user disputed his refund amounts @@ -64,7 +60,11 @@ interface ICoreStateRegistry { /// @param finalAmount_ is the final amount of tokens received /// @param amount_ is the indicated amount of tokens to be received /// @param maxSlippage_ is the amount of acceptable slippage for the transaction - function validateSlippage(uint256 finalAmount_, uint256 amount_, uint256 maxSlippage_) + function validateSlippage( + uint256 finalAmount_, + uint256 amount_, + uint256 maxSlippage_ + ) external view returns (bool); diff --git a/src/interfaces/IDstSwapper.sol b/src/interfaces/IDstSwapper.sol index 62bad9b90..fefd11f97 100644 --- a/src/interfaces/IDstSwapper.sol +++ b/src/interfaces/IDstSwapper.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for DstSwapper /// @author Zeropoint Labs interface IDstSwapper { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IEmergencyQueue.sol b/src/interfaces/IEmergencyQueue.sol index 5d2daa982..8dcd2dd15 100644 --- a/src/interfaces/IEmergencyQueue.sol +++ b/src/interfaces/IEmergencyQueue.sol @@ -7,7 +7,6 @@ import { InitSingleVaultData } from "src/types/DataTypes.sol"; /// @dev Interface for EmergencyQueue /// @author ZeroPoint Labs interface IEmergencyQueue { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IPayMaster.sol b/src/interfaces/IPayMaster.sol index 50448e658..8f7689dbe 100644 --- a/src/interfaces/IPayMaster.sol +++ b/src/interfaces/IPayMaster.sol @@ -7,7 +7,6 @@ import { LiqRequest } from "src/types/DataTypes.sol"; /// @dev Interface for PayMaster /// @author ZeroPoint Labs interface IPayMaster { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IQuorumManager.sol b/src/interfaces/IQuorumManager.sol index 813d1d0e2..143f4fd52 100644 --- a/src/interfaces/IQuorumManager.sol +++ b/src/interfaces/IQuorumManager.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for QuorumManager /// @author ZeroPoint Labs interface IQuorumManager { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/ISuperPositions.sol b/src/interfaces/ISuperPositions.sol index 1f1dd069a..1c3c8d2ea 100644 --- a/src/interfaces/ISuperPositions.sol +++ b/src/interfaces/ISuperPositions.sol @@ -8,7 +8,6 @@ import { AMBMessage } from "../types/DataTypes.sol"; /// @dev Interface for SuperPositions /// @author Zeropoint Labs interface ISuperPositions is IERC1155A { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -17,7 +16,7 @@ interface ISuperPositions is IERC1155A { uint256 txInfo; address receiverAddressSP; } - + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/ISuperRBAC.sol b/src/interfaces/ISuperRBAC.sol index 3b9a6abb1..98f06ceba 100644 --- a/src/interfaces/ISuperRBAC.sol +++ b/src/interfaces/ISuperRBAC.sol @@ -7,7 +7,6 @@ import { IAccessControl } from "openzeppelin-contracts/contracts/access/IAccessC /// @dev Interface for SuperRBAC /// @author Zeropoint Labs interface ISuperRBAC is IAccessControl { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/ISuperformFactory.sol b/src/interfaces/ISuperformFactory.sol index dc1705e80..ae5a47ac4 100644 --- a/src/interfaces/ISuperformFactory.sol +++ b/src/interfaces/ISuperformFactory.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for SuperformFactory /// @author ZeroPoint Labs interface ISuperformFactory { - ////////////////////////////////////////////////////////////// // CONSTANTS // ////////////////////////////////////////////////////////////// diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 63b110330..440bce881 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -434,15 +434,13 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou r.amount = requestedAmount_; - emit RefundInitiated( - routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_ - ); + emit RefundInitiated(routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_); } /// @inheritdoc ISuperformRouterPlusAsync function approveRefund(uint256 routerPlusPayloadId_) external onlyCoreStateRegistryRescuer { if (approvedRefund[routerPlusPayloadId_]) revert REFUND_ALREADY_APPROVED(); - + Refund memory r = refunds[routerPlusPayloadId_]; XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; diff --git a/src/vendor/lifi/celer-network/MsgDataTypes.sol b/src/vendor/lifi/celer-network/MsgDataTypes.sol index 7a63d0ac6..c3ca0a913 100644 --- a/src/vendor/lifi/celer-network/MsgDataTypes.sol +++ b/src/vendor/lifi/celer-network/MsgDataTypes.sol @@ -26,6 +26,7 @@ library MsgDataTypes { PegWithdraw, // withdraw from original token vault PegV2Mint, // mint through pegged token bridge v2 PegV2Withdraw // withdraw from original token vault v2 + } enum MsgType { @@ -39,6 +40,7 @@ library MsgDataTypes { Fail, Fallback, Pending // transient state within a transaction + } struct TransferInfo { diff --git a/test/unit/payments/PaymentHelper.t.sol b/test/unit/payments/PaymentHelper.t.sol index bba518bb0..503aea624 100644 --- a/test/unit/payments/PaymentHelper.t.sol +++ b/test/unit/payments/PaymentHelper.t.sol @@ -569,7 +569,6 @@ contract PaymentHelperTest is ProtocolActions { assertEq(fees3, 0); } - function test_estimateSingleDirectMultiVault() public view { /// @dev scenario: single vault withdrawal diff --git a/test/utils/InvariantProtocolActions.sol b/test/utils/InvariantProtocolActions.sol index dcf4bb586..043b4753a 100644 --- a/test/utils/InvariantProtocolActions.sol +++ b/test/utils/InvariantProtocolActions.sol @@ -1189,9 +1189,7 @@ abstract contract InvariantProtocolActions is CommonProtocolActions { uint256 decimal3; } - function _buildSingleVaultWithdrawCallData( - SingleVaultCallDataArgs memory args - ) + function _buildSingleVaultWithdrawCallData(SingleVaultCallDataArgs memory args) internal returns (SingleVaultSFData memory superformData) { From 7ead1462da87b0893d1b5fe2db6503d2ad55f805 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:32:50 +0200 Subject: [PATCH 22/51] style: formatting --- .../forge-scripts/safe/lib/DelegatePrank.sol | 41 +++++++++---------- src/BaseForm.sol | 5 ++- .../extensions/AsyncStateRegistry.sol | 6 ++- src/crosschain-data/utils/QuorumManager.sol | 3 +- .../socket/SocketOneInchValidator.sol | 3 +- src/forms/ERC4626FormImplementation.sol | 6 ++- src/forms/interfaces/IERC4626Form.sol | 3 +- src/interfaces/IAsyncStateRegistry.sol | 6 ++- src/interfaces/IBaseForm.sol | 3 +- src/interfaces/IBaseRouter.sol | 3 +- .../IBroadcastAmbImplementation.sol | 3 +- src/interfaces/ICoreStateRegistry.sol | 14 +++---- src/interfaces/IDstSwapper.sol | 3 +- src/interfaces/IEmergencyQueue.sol | 3 +- src/interfaces/IPayMaster.sol | 3 +- src/interfaces/IQuorumManager.sol | 3 +- src/interfaces/ISuperPositions.sol | 5 ++- src/interfaces/ISuperRBAC.sol | 3 +- src/interfaces/ISuperformFactory.sol | 3 +- .../lifi/celer-network/MsgDataTypes.sol | 4 +- test/unit/payments/PaymentHelper.t.sol | 3 +- 21 files changed, 72 insertions(+), 54 deletions(-) diff --git a/script/forge-scripts/safe/lib/DelegatePrank.sol b/script/forge-scripts/safe/lib/DelegatePrank.sol index 6df91ee9b..c90184618 100644 --- a/script/forge-scripts/safe/lib/DelegatePrank.sol +++ b/script/forge-scripts/safe/lib/DelegatePrank.sol @@ -20,28 +20,27 @@ import "forge-std/console.sol"; */ contract DelegatePrank is CommonBase { - Delegator delegator = makeDelegator(); - - function makeDelegator() internal returns (Delegator) { - return new Delegator(); - } - - function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { - bytes memory code = from.code; - vm.etch(from, address(delegator).code); - (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall, (to, cd, code))); - } + Delegator delegator = makeDelegator(); + function makeDelegator() internal returns (Delegator) { + return new Delegator(); + } + + function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { + bytes memory code = from.code; + vm.etch(from,address(delegator).code); + (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall,(to,cd,code))); + } } contract Delegator is CommonBase { - function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { - vm.etch(address(this), code); - assembly ("memory-safe") { - let result := delegatecall(gas(), dest, add(cd, 32), mload(cd), 0, 0) - returndatacopy(0, 0, returndatasize()) - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } - } + function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { + vm.etch(address(this),code); + assembly ("memory-safe") { + let result := delegatecall(gas(), dest, add(cd,32), mload(cd), 0, 0) + returndatacopy(0, 0, returndatasize()) + switch result + case 0 { revert(0, returndatasize()) } + default { return(0, returndatasize()) } } -} + } +} \ No newline at end of file diff --git a/src/BaseForm.sol b/src/BaseForm.sol index 31551584b..4b5c33961 100644 --- a/src/BaseForm.sol +++ b/src/BaseForm.sol @@ -16,6 +16,7 @@ import { IERC165 } from "openzeppelin-contracts/contracts/utils/introspection/IE /// @dev Abstract contract to be inherited by different Form implementations /// @author Zeropoint Labs abstract contract BaseForm is IBaseForm, Initializable, ERC165 { + using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -253,7 +254,7 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { } /// @dev Checks if the Form implementation has the appropriate interface support - /// @param interfaceId_ is the interfaceId to check + /// @param interfaceId_ is the interfaceId to check function supportsInterface(bytes4 interfaceId_) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId_ == type(IBaseForm).interfaceId || super.supportsInterface(interfaceId_); } @@ -317,4 +318,4 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { return ISuperformFactory(factory).isFormImplementationPaused(formImplementationId_); } -} +} \ No newline at end of file diff --git a/src/crosschain-data/extensions/AsyncStateRegistry.sol b/src/crosschain-data/extensions/AsyncStateRegistry.sol index 18afd3ac0..abf2523c3 100644 --- a/src/crosschain-data/extensions/AsyncStateRegistry.sol +++ b/src/crosschain-data/extensions/AsyncStateRegistry.sol @@ -361,7 +361,9 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } /// @inheritdoc IAsyncStateRegistry - function getSyncWithdrawTxDataPayload(uint256 payloadId_) + function getSyncWithdrawTxDataPayload( + uint256 payloadId_ + ) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_) @@ -500,4 +502,4 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } } } -} +} \ No newline at end of file diff --git a/src/crosschain-data/utils/QuorumManager.sol b/src/crosschain-data/utils/QuorumManager.sol index b84e48137..a9feff3b6 100644 --- a/src/crosschain-data/utils/QuorumManager.sol +++ b/src/crosschain-data/utils/QuorumManager.sol @@ -8,6 +8,7 @@ import { Error } from "src/libraries/Error.sol"; /// @dev Quorum thresholds using in sending proofs from chain to chain /// @author ZeroPoint Labs abstract contract QuorumManager is IQuorumManager { + ////////////////////////////////////////////////////////////// // STATE VARIABLES // ////////////////////////////////////////////////////////////// @@ -33,4 +34,4 @@ abstract contract QuorumManager is IQuorumManager { /// @inheritdoc IQuorumManager function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external virtual; -} +} \ No newline at end of file diff --git a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol index 15a042f43..59ad9a407 100644 --- a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol +++ b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol @@ -9,6 +9,7 @@ import { ISocketOneInchImpl } from "src/vendor/socket/ISocketOneInchImpl.sol"; /// @dev Asserts Socket same-chain txData is valid /// @author Zeropoint Labs contract SocketOneInchValidator is BridgeValidator { + ////////////////////////////////////////////////////////////// // CONSTRUCTOR // ////////////////////////////////////////////////////////////// @@ -94,4 +95,4 @@ contract SocketOneInchValidator is BridgeValidator { function _parseCallData(bytes calldata callData) internal pure returns (bytes calldata) { return callData[4:]; } -} +} \ No newline at end of file diff --git a/src/forms/ERC4626FormImplementation.sol b/src/forms/ERC4626FormImplementation.sol index 1c50775f7..3eb1b71d1 100644 --- a/src/forms/ERC4626FormImplementation.sol +++ b/src/forms/ERC4626FormImplementation.sol @@ -16,6 +16,7 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Has common ERC4626 internal functions that can be re-used by implementations /// @author Zeropoint Labs abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { + using SafeERC20 for IERC20; using SafeERC20 for IERC4626; using DataLib for uint256; @@ -228,7 +229,7 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { /// superform data if ( vars.assetDifference * ENTIRE_SLIPPAGE - < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) + < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) ) { revert Error.DIRECT_DEPOSIT_SWAP_FAILED(); } @@ -270,6 +271,7 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { } function _processDirectWithdraw(InitSingleVaultData memory singleVaultData_) internal returns (uint256 assets) { + DirectWithdrawLocalVars memory vars; /// @dev if there is no txData, on withdraws the receiver is receiverAddress, otherwise it @@ -490,4 +492,4 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { emit FormDustForwardedToPaymaster(token_, dust); } } -} +} \ No newline at end of file diff --git a/src/forms/interfaces/IERC4626Form.sol b/src/forms/interfaces/IERC4626Form.sol index 9891d2574..0e308027f 100644 --- a/src/forms/interfaces/IERC4626Form.sol +++ b/src/forms/interfaces/IERC4626Form.sol @@ -7,6 +7,7 @@ import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol" /// @dev Interface for ERC4626Form /// @author Zeropoint Labs interface IERC4626Form is IERC20 { + ////////////////////////////////////////////////////////////// // EXTERNAL VIEW FUNCTIONS // ////////////////////////////////////////////////////////////// @@ -38,4 +39,4 @@ interface IERC4626Form is IERC20 { function previewWithdrawFrom(uint256 assets_) external view returns (uint256); function previewRedeemFrom(uint256 shares_) external view returns (uint256); -} +} \ No newline at end of file diff --git a/src/interfaces/IAsyncStateRegistry.sol b/src/interfaces/IAsyncStateRegistry.sol index cee773fce..a091e4083 100644 --- a/src/interfaces/IAsyncStateRegistry.sol +++ b/src/interfaces/IAsyncStateRegistry.sol @@ -101,7 +101,9 @@ interface IAsyncStateRegistry { /// @notice retrieves the sync withdraw txData payload for a given payload ID /// @param payloadId_ The ID of the payload /// @return syncWithdrawTxDataPayload_ for the specified payload ID - function getSyncWithdrawTxDataPayload(uint256 payloadId_) + function getSyncWithdrawTxDataPayload( + uint256 payloadId_ + ) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_); @@ -149,4 +151,4 @@ interface IAsyncStateRegistry { /// @param payloadId_ is the id of the payload to finalize /// @param txData_ is the off-chain generated transaction data function processSyncWithdrawWithUpdatedTxData(uint256 payloadId_, bytes memory txData_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/IBaseForm.sol b/src/interfaces/IBaseForm.sol index 5b380793c..f22a4d59c 100644 --- a/src/interfaces/IBaseForm.sol +++ b/src/interfaces/IBaseForm.sol @@ -9,6 +9,7 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Interface for BaseForm /// @author ZeroPoint Labs interface IBaseForm is IERC165 { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -156,4 +157,4 @@ interface IBaseForm is IERC165 { /// @dev moves all dust in the contract to Paymaster contract /// @param token_ The address of the token to forward function forwardDustToPaymaster(address token_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IBaseRouter.sol b/src/interfaces/IBaseRouter.sol index 3a651f584..5f43ca51e 100644 --- a/src/interfaces/IBaseRouter.sol +++ b/src/interfaces/IBaseRouter.sol @@ -7,6 +7,7 @@ import "src/types/DataTypes.sol"; /// @dev Interface for abstract BaseRouter /// @author Zeropoint Labs interface IBaseRouter { + ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// @@ -62,4 +63,4 @@ interface IBaseRouter { /// @dev Forwards dust to Paymaster /// @param token_ the token to forward function forwardDustToPaymaster(address token_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IBroadcastAmbImplementation.sol b/src/interfaces/IBroadcastAmbImplementation.sol index 83de6ca83..1df089dd3 100644 --- a/src/interfaces/IBroadcastAmbImplementation.sol +++ b/src/interfaces/IBroadcastAmbImplementation.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for AMBs used in Broadcasting /// @author ZeroPoint Labs interface IBroadcastAmbImplementation { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -32,4 +33,4 @@ interface IBroadcastAmbImplementation { /// @param message_ is the cross-chain message to be broadcasted /// @param extraData_ is optional broadcast override information function broadcastPayload(address srcSender_, bytes memory message_, bytes memory extraData_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/ICoreStateRegistry.sol b/src/interfaces/ICoreStateRegistry.sol index a9775e171..f6cee7669 100644 --- a/src/interfaces/ICoreStateRegistry.sol +++ b/src/interfaces/ICoreStateRegistry.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for CoreStateRegistry /// @author ZeroPoint Labs interface ICoreStateRegistry { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -33,7 +34,10 @@ interface ICoreStateRegistry { /// @dev is emitted when a rescue is proposed for failed deposits in a payload event RescueProposed( - uint256 indexed payloadId, uint256[] superformIds, uint256[] proposedAmount, uint256 proposedTime + uint256 indexed payloadId, + uint256[] superformIds, + uint256[] proposedAmount, + uint256 proposedTime ); /// @dev is emitted when an user disputed his refund amounts @@ -60,11 +64,7 @@ interface ICoreStateRegistry { /// @param finalAmount_ is the final amount of tokens received /// @param amount_ is the indicated amount of tokens to be received /// @param maxSlippage_ is the amount of acceptable slippage for the transaction - function validateSlippage( - uint256 finalAmount_, - uint256 amount_, - uint256 maxSlippage_ - ) + function validateSlippage(uint256 finalAmount_, uint256 amount_, uint256 maxSlippage_) external view returns (bool); @@ -103,4 +103,4 @@ interface ICoreStateRegistry { /// @dev allows anyone to settle refunds for unprocessed/failed deposits past the challenge period /// @param payloadId_ is the identifier of the cross-chain payload function finalizeRescueFailedDeposits(uint256 payloadId_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IDstSwapper.sol b/src/interfaces/IDstSwapper.sol index fefd11f97..ef7b254e1 100644 --- a/src/interfaces/IDstSwapper.sol +++ b/src/interfaces/IDstSwapper.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for DstSwapper /// @author Zeropoint Labs interface IDstSwapper { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -101,4 +102,4 @@ interface IDstSwapper { /// @param interimToken_ is the refund token /// @param amount_ is the refund amount function processFailedTx(address user_, address interimToken_, uint256 amount_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IEmergencyQueue.sol b/src/interfaces/IEmergencyQueue.sol index 8dcd2dd15..ac8ba2767 100644 --- a/src/interfaces/IEmergencyQueue.sol +++ b/src/interfaces/IEmergencyQueue.sol @@ -7,6 +7,7 @@ import { InitSingleVaultData } from "src/types/DataTypes.sol"; /// @dev Interface for EmergencyQueue /// @author ZeroPoint Labs interface IEmergencyQueue { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -47,4 +48,4 @@ interface IEmergencyQueue { /// @dev called by emergency admin to batch process queued withdrawals /// @param ids_ is the array of identifiers of the queued actions function batchExecuteQueuedWithdrawal(uint256[] memory ids_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IPayMaster.sol b/src/interfaces/IPayMaster.sol index 8f7689dbe..c78878ac3 100644 --- a/src/interfaces/IPayMaster.sol +++ b/src/interfaces/IPayMaster.sol @@ -7,6 +7,7 @@ import { LiqRequest } from "src/types/DataTypes.sol"; /// @dev Interface for PayMaster /// @author ZeroPoint Labs interface IPayMaster { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -50,4 +51,4 @@ interface IPayMaster { /// @dev accepts payment from user /// @param user_ is the wallet address of the paying user function makePayment(address user_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/IQuorumManager.sol b/src/interfaces/IQuorumManager.sol index 143f4fd52..b85bdaa25 100644 --- a/src/interfaces/IQuorumManager.sol +++ b/src/interfaces/IQuorumManager.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for QuorumManager /// @author ZeroPoint Labs interface IQuorumManager { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -33,4 +34,4 @@ interface IQuorumManager { /// @param quorum_ the minimum number of message bridges required for processing /// NOTE: overriding child contracts should handle the sender validation & setting of message quorum function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperPositions.sol b/src/interfaces/ISuperPositions.sol index 1c3c8d2ea..d5d7914aa 100644 --- a/src/interfaces/ISuperPositions.sol +++ b/src/interfaces/ISuperPositions.sol @@ -8,6 +8,7 @@ import { AMBMessage } from "../types/DataTypes.sol"; /// @dev Interface for SuperPositions /// @author Zeropoint Labs interface ISuperPositions is IERC1155A { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -16,7 +17,7 @@ interface ISuperPositions is IERC1155A { uint256 txInfo; address receiverAddressSP; } - + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -97,4 +98,4 @@ interface ISuperPositions is IERC1155A { /// @dev allows to create sERC0 using broadcast state registry /// @param data_ is the crosschain payload function stateSyncBroadcast(bytes memory data_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperRBAC.sol b/src/interfaces/ISuperRBAC.sol index 98f06ceba..5d54de9ef 100644 --- a/src/interfaces/ISuperRBAC.sol +++ b/src/interfaces/ISuperRBAC.sol @@ -7,6 +7,7 @@ import { IAccessControl } from "openzeppelin-contracts/contracts/access/IAccessC /// @dev Interface for SuperRBAC /// @author Zeropoint Labs interface ISuperRBAC is IAccessControl { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -110,4 +111,4 @@ interface ISuperRBAC is IAccessControl { /// @dev allows sync of global roles from different chains using broadcast registry /// @notice may not work for all roles function stateSyncBroadcast(bytes memory data_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperformFactory.sol b/src/interfaces/ISuperformFactory.sol index ae5a47ac4..79c770093 100644 --- a/src/interfaces/ISuperformFactory.sol +++ b/src/interfaces/ISuperformFactory.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for SuperformFactory /// @author ZeroPoint Labs interface ISuperformFactory { + ////////////////////////////////////////////////////////////// // CONSTANTS // ////////////////////////////////////////////////////////////// @@ -139,4 +140,4 @@ interface ISuperformFactory { ) external payable; -} +} \ No newline at end of file diff --git a/src/vendor/lifi/celer-network/MsgDataTypes.sol b/src/vendor/lifi/celer-network/MsgDataTypes.sol index c3ca0a913..5427869e5 100644 --- a/src/vendor/lifi/celer-network/MsgDataTypes.sol +++ b/src/vendor/lifi/celer-network/MsgDataTypes.sol @@ -26,7 +26,6 @@ library MsgDataTypes { PegWithdraw, // withdraw from original token vault PegV2Mint, // mint through pegged token bridge v2 PegV2Withdraw // withdraw from original token vault v2 - } enum MsgType { @@ -40,7 +39,6 @@ library MsgDataTypes { Fail, Fallback, Pending // transient state within a transaction - } struct TransferInfo { @@ -93,4 +91,4 @@ library MsgDataTypes { address[] signers; uint256[] powers; } -} +} \ No newline at end of file diff --git a/test/unit/payments/PaymentHelper.t.sol b/test/unit/payments/PaymentHelper.t.sol index 503aea624..3c9e4d87b 100644 --- a/test/unit/payments/PaymentHelper.t.sol +++ b/test/unit/payments/PaymentHelper.t.sol @@ -569,6 +569,7 @@ contract PaymentHelperTest is ProtocolActions { assertEq(fees3, 0); } + function test_estimateSingleDirectMultiVault() public view { /// @dev scenario: single vault withdrawal @@ -1663,4 +1664,4 @@ contract PaymentHelperTest is ProtocolActions { superformId_ |= uint256(formImplementationId_) << 160; superformId_ |= uint256(chainId_) << 192; } -} +} \ No newline at end of file From fcd9edf6d10e46f024131bd4f76304831af848cf Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:51:23 +0200 Subject: [PATCH 23/51] Revert "chore: formatting" This reverts commit 094e8d8b83f8499b7ec29d00b170be1bad54dcd1. --- .../debridge/libraries/DeBridgeError.sol | 2 +- src/router-plus/SuperformRouterPlusAsync.sol | 6 ++++-- test/utils/InvariantProtocolActions.sol | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol b/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol index f5e85b308..704cf5d06 100644 --- a/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol +++ b/src/crosschain-liquidity/debridge/libraries/DeBridgeError.sol @@ -35,4 +35,4 @@ library DeBridgeError { /// @dev if the swap router is invalid error INVALID_SWAP_ROUTER(); -} +} \ No newline at end of file diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 440bce881..63b110330 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -434,13 +434,15 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou r.amount = requestedAmount_; - emit RefundInitiated(routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_); + emit RefundInitiated( + routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_ + ); } /// @inheritdoc ISuperformRouterPlusAsync function approveRefund(uint256 routerPlusPayloadId_) external onlyCoreStateRegistryRescuer { if (approvedRefund[routerPlusPayloadId_]) revert REFUND_ALREADY_APPROVED(); - + Refund memory r = refunds[routerPlusPayloadId_]; XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; diff --git a/test/utils/InvariantProtocolActions.sol b/test/utils/InvariantProtocolActions.sol index 043b4753a..dcf4bb586 100644 --- a/test/utils/InvariantProtocolActions.sol +++ b/test/utils/InvariantProtocolActions.sol @@ -1189,7 +1189,9 @@ abstract contract InvariantProtocolActions is CommonProtocolActions { uint256 decimal3; } - function _buildSingleVaultWithdrawCallData(SingleVaultCallDataArgs memory args) + function _buildSingleVaultWithdrawCallData( + SingleVaultCallDataArgs memory args + ) internal returns (SingleVaultSFData memory superformData) { From 0efc2baa649bb17580d3fb66d77a04c7df8fe661 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:54:39 +0200 Subject: [PATCH 24/51] Revert "style: formatting" This reverts commit 7ead1462da87b0893d1b5fe2db6503d2ad55f805. --- .../forge-scripts/safe/lib/DelegatePrank.sol | 41 ++++++++++--------- src/BaseForm.sol | 5 +-- .../extensions/AsyncStateRegistry.sol | 6 +-- src/crosschain-data/utils/QuorumManager.sol | 3 +- .../socket/SocketOneInchValidator.sol | 3 +- src/forms/ERC4626FormImplementation.sol | 6 +-- src/forms/interfaces/IERC4626Form.sol | 3 +- src/interfaces/IAsyncStateRegistry.sol | 6 +-- src/interfaces/IBaseForm.sol | 3 +- src/interfaces/IBaseRouter.sol | 3 +- .../IBroadcastAmbImplementation.sol | 3 +- src/interfaces/ICoreStateRegistry.sol | 14 +++---- src/interfaces/IDstSwapper.sol | 3 +- src/interfaces/IEmergencyQueue.sol | 3 +- src/interfaces/IPayMaster.sol | 3 +- src/interfaces/IQuorumManager.sol | 3 +- src/interfaces/ISuperPositions.sol | 5 +-- src/interfaces/ISuperRBAC.sol | 3 +- src/interfaces/ISuperformFactory.sol | 3 +- .../lifi/celer-network/MsgDataTypes.sol | 4 +- test/unit/payments/PaymentHelper.t.sol | 3 +- 21 files changed, 54 insertions(+), 72 deletions(-) diff --git a/script/forge-scripts/safe/lib/DelegatePrank.sol b/script/forge-scripts/safe/lib/DelegatePrank.sol index c90184618..6df91ee9b 100644 --- a/script/forge-scripts/safe/lib/DelegatePrank.sol +++ b/script/forge-scripts/safe/lib/DelegatePrank.sol @@ -20,27 +20,28 @@ import "forge-std/console.sol"; */ contract DelegatePrank is CommonBase { - Delegator delegator = makeDelegator(); - function makeDelegator() internal returns (Delegator) { - return new Delegator(); - } - - function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { - bytes memory code = from.code; - vm.etch(from,address(delegator).code); - (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall,(to,cd,code))); - } + Delegator delegator = makeDelegator(); + + function makeDelegator() internal returns (Delegator) { + return new Delegator(); + } + + function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { + bytes memory code = from.code; + vm.etch(from, address(delegator).code); + (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall, (to, cd, code))); + } } contract Delegator is CommonBase { - function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { - vm.etch(address(this),code); - assembly ("memory-safe") { - let result := delegatecall(gas(), dest, add(cd,32), mload(cd), 0, 0) - returndatacopy(0, 0, returndatasize()) - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } + function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { + vm.etch(address(this), code); + assembly ("memory-safe") { + let result := delegatecall(gas(), dest, add(cd, 32), mload(cd), 0, 0) + returndatacopy(0, 0, returndatasize()) + switch result + case 0 { revert(0, returndatasize()) } + default { return(0, returndatasize()) } + } } - } -} \ No newline at end of file +} diff --git a/src/BaseForm.sol b/src/BaseForm.sol index 4b5c33961..31551584b 100644 --- a/src/BaseForm.sol +++ b/src/BaseForm.sol @@ -16,7 +16,6 @@ import { IERC165 } from "openzeppelin-contracts/contracts/utils/introspection/IE /// @dev Abstract contract to be inherited by different Form implementations /// @author Zeropoint Labs abstract contract BaseForm is IBaseForm, Initializable, ERC165 { - using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -254,7 +253,7 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { } /// @dev Checks if the Form implementation has the appropriate interface support - /// @param interfaceId_ is the interfaceId to check + /// @param interfaceId_ is the interfaceId to check function supportsInterface(bytes4 interfaceId_) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId_ == type(IBaseForm).interfaceId || super.supportsInterface(interfaceId_); } @@ -318,4 +317,4 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { return ISuperformFactory(factory).isFormImplementationPaused(formImplementationId_); } -} \ No newline at end of file +} diff --git a/src/crosschain-data/extensions/AsyncStateRegistry.sol b/src/crosschain-data/extensions/AsyncStateRegistry.sol index abf2523c3..18afd3ac0 100644 --- a/src/crosschain-data/extensions/AsyncStateRegistry.sol +++ b/src/crosschain-data/extensions/AsyncStateRegistry.sol @@ -361,9 +361,7 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } /// @inheritdoc IAsyncStateRegistry - function getSyncWithdrawTxDataPayload( - uint256 payloadId_ - ) + function getSyncWithdrawTxDataPayload(uint256 payloadId_) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_) @@ -502,4 +500,4 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } } } -} \ No newline at end of file +} diff --git a/src/crosschain-data/utils/QuorumManager.sol b/src/crosschain-data/utils/QuorumManager.sol index a9feff3b6..b84e48137 100644 --- a/src/crosschain-data/utils/QuorumManager.sol +++ b/src/crosschain-data/utils/QuorumManager.sol @@ -8,7 +8,6 @@ import { Error } from "src/libraries/Error.sol"; /// @dev Quorum thresholds using in sending proofs from chain to chain /// @author ZeroPoint Labs abstract contract QuorumManager is IQuorumManager { - ////////////////////////////////////////////////////////////// // STATE VARIABLES // ////////////////////////////////////////////////////////////// @@ -34,4 +33,4 @@ abstract contract QuorumManager is IQuorumManager { /// @inheritdoc IQuorumManager function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external virtual; -} \ No newline at end of file +} diff --git a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol index 59ad9a407..15a042f43 100644 --- a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol +++ b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol @@ -9,7 +9,6 @@ import { ISocketOneInchImpl } from "src/vendor/socket/ISocketOneInchImpl.sol"; /// @dev Asserts Socket same-chain txData is valid /// @author Zeropoint Labs contract SocketOneInchValidator is BridgeValidator { - ////////////////////////////////////////////////////////////// // CONSTRUCTOR // ////////////////////////////////////////////////////////////// @@ -95,4 +94,4 @@ contract SocketOneInchValidator is BridgeValidator { function _parseCallData(bytes calldata callData) internal pure returns (bytes calldata) { return callData[4:]; } -} \ No newline at end of file +} diff --git a/src/forms/ERC4626FormImplementation.sol b/src/forms/ERC4626FormImplementation.sol index 3eb1b71d1..1c50775f7 100644 --- a/src/forms/ERC4626FormImplementation.sol +++ b/src/forms/ERC4626FormImplementation.sol @@ -16,7 +16,6 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Has common ERC4626 internal functions that can be re-used by implementations /// @author Zeropoint Labs abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { - using SafeERC20 for IERC20; using SafeERC20 for IERC4626; using DataLib for uint256; @@ -229,7 +228,7 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { /// superform data if ( vars.assetDifference * ENTIRE_SLIPPAGE - < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) + < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) ) { revert Error.DIRECT_DEPOSIT_SWAP_FAILED(); } @@ -271,7 +270,6 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { } function _processDirectWithdraw(InitSingleVaultData memory singleVaultData_) internal returns (uint256 assets) { - DirectWithdrawLocalVars memory vars; /// @dev if there is no txData, on withdraws the receiver is receiverAddress, otherwise it @@ -492,4 +490,4 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { emit FormDustForwardedToPaymaster(token_, dust); } } -} \ No newline at end of file +} diff --git a/src/forms/interfaces/IERC4626Form.sol b/src/forms/interfaces/IERC4626Form.sol index 0e308027f..9891d2574 100644 --- a/src/forms/interfaces/IERC4626Form.sol +++ b/src/forms/interfaces/IERC4626Form.sol @@ -7,7 +7,6 @@ import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol" /// @dev Interface for ERC4626Form /// @author Zeropoint Labs interface IERC4626Form is IERC20 { - ////////////////////////////////////////////////////////////// // EXTERNAL VIEW FUNCTIONS // ////////////////////////////////////////////////////////////// @@ -39,4 +38,4 @@ interface IERC4626Form is IERC20 { function previewWithdrawFrom(uint256 assets_) external view returns (uint256); function previewRedeemFrom(uint256 shares_) external view returns (uint256); -} \ No newline at end of file +} diff --git a/src/interfaces/IAsyncStateRegistry.sol b/src/interfaces/IAsyncStateRegistry.sol index a091e4083..cee773fce 100644 --- a/src/interfaces/IAsyncStateRegistry.sol +++ b/src/interfaces/IAsyncStateRegistry.sol @@ -101,9 +101,7 @@ interface IAsyncStateRegistry { /// @notice retrieves the sync withdraw txData payload for a given payload ID /// @param payloadId_ The ID of the payload /// @return syncWithdrawTxDataPayload_ for the specified payload ID - function getSyncWithdrawTxDataPayload( - uint256 payloadId_ - ) + function getSyncWithdrawTxDataPayload(uint256 payloadId_) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_); @@ -151,4 +149,4 @@ interface IAsyncStateRegistry { /// @param payloadId_ is the id of the payload to finalize /// @param txData_ is the off-chain generated transaction data function processSyncWithdrawWithUpdatedTxData(uint256 payloadId_, bytes memory txData_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/IBaseForm.sol b/src/interfaces/IBaseForm.sol index f22a4d59c..5b380793c 100644 --- a/src/interfaces/IBaseForm.sol +++ b/src/interfaces/IBaseForm.sol @@ -9,7 +9,6 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Interface for BaseForm /// @author ZeroPoint Labs interface IBaseForm is IERC165 { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -157,4 +156,4 @@ interface IBaseForm is IERC165 { /// @dev moves all dust in the contract to Paymaster contract /// @param token_ The address of the token to forward function forwardDustToPaymaster(address token_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IBaseRouter.sol b/src/interfaces/IBaseRouter.sol index 5f43ca51e..3a651f584 100644 --- a/src/interfaces/IBaseRouter.sol +++ b/src/interfaces/IBaseRouter.sol @@ -7,7 +7,6 @@ import "src/types/DataTypes.sol"; /// @dev Interface for abstract BaseRouter /// @author Zeropoint Labs interface IBaseRouter { - ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// @@ -63,4 +62,4 @@ interface IBaseRouter { /// @dev Forwards dust to Paymaster /// @param token_ the token to forward function forwardDustToPaymaster(address token_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IBroadcastAmbImplementation.sol b/src/interfaces/IBroadcastAmbImplementation.sol index 1df089dd3..83de6ca83 100644 --- a/src/interfaces/IBroadcastAmbImplementation.sol +++ b/src/interfaces/IBroadcastAmbImplementation.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for AMBs used in Broadcasting /// @author ZeroPoint Labs interface IBroadcastAmbImplementation { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -33,4 +32,4 @@ interface IBroadcastAmbImplementation { /// @param message_ is the cross-chain message to be broadcasted /// @param extraData_ is optional broadcast override information function broadcastPayload(address srcSender_, bytes memory message_, bytes memory extraData_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/ICoreStateRegistry.sol b/src/interfaces/ICoreStateRegistry.sol index f6cee7669..a9775e171 100644 --- a/src/interfaces/ICoreStateRegistry.sol +++ b/src/interfaces/ICoreStateRegistry.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for CoreStateRegistry /// @author ZeroPoint Labs interface ICoreStateRegistry { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -34,10 +33,7 @@ interface ICoreStateRegistry { /// @dev is emitted when a rescue is proposed for failed deposits in a payload event RescueProposed( - uint256 indexed payloadId, - uint256[] superformIds, - uint256[] proposedAmount, - uint256 proposedTime + uint256 indexed payloadId, uint256[] superformIds, uint256[] proposedAmount, uint256 proposedTime ); /// @dev is emitted when an user disputed his refund amounts @@ -64,7 +60,11 @@ interface ICoreStateRegistry { /// @param finalAmount_ is the final amount of tokens received /// @param amount_ is the indicated amount of tokens to be received /// @param maxSlippage_ is the amount of acceptable slippage for the transaction - function validateSlippage(uint256 finalAmount_, uint256 amount_, uint256 maxSlippage_) + function validateSlippage( + uint256 finalAmount_, + uint256 amount_, + uint256 maxSlippage_ + ) external view returns (bool); @@ -103,4 +103,4 @@ interface ICoreStateRegistry { /// @dev allows anyone to settle refunds for unprocessed/failed deposits past the challenge period /// @param payloadId_ is the identifier of the cross-chain payload function finalizeRescueFailedDeposits(uint256 payloadId_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IDstSwapper.sol b/src/interfaces/IDstSwapper.sol index ef7b254e1..fefd11f97 100644 --- a/src/interfaces/IDstSwapper.sol +++ b/src/interfaces/IDstSwapper.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for DstSwapper /// @author Zeropoint Labs interface IDstSwapper { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -102,4 +101,4 @@ interface IDstSwapper { /// @param interimToken_ is the refund token /// @param amount_ is the refund amount function processFailedTx(address user_, address interimToken_, uint256 amount_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IEmergencyQueue.sol b/src/interfaces/IEmergencyQueue.sol index ac8ba2767..8dcd2dd15 100644 --- a/src/interfaces/IEmergencyQueue.sol +++ b/src/interfaces/IEmergencyQueue.sol @@ -7,7 +7,6 @@ import { InitSingleVaultData } from "src/types/DataTypes.sol"; /// @dev Interface for EmergencyQueue /// @author ZeroPoint Labs interface IEmergencyQueue { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -48,4 +47,4 @@ interface IEmergencyQueue { /// @dev called by emergency admin to batch process queued withdrawals /// @param ids_ is the array of identifiers of the queued actions function batchExecuteQueuedWithdrawal(uint256[] memory ids_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IPayMaster.sol b/src/interfaces/IPayMaster.sol index c78878ac3..8f7689dbe 100644 --- a/src/interfaces/IPayMaster.sol +++ b/src/interfaces/IPayMaster.sol @@ -7,7 +7,6 @@ import { LiqRequest } from "src/types/DataTypes.sol"; /// @dev Interface for PayMaster /// @author ZeroPoint Labs interface IPayMaster { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -51,4 +50,4 @@ interface IPayMaster { /// @dev accepts payment from user /// @param user_ is the wallet address of the paying user function makePayment(address user_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/IQuorumManager.sol b/src/interfaces/IQuorumManager.sol index b85bdaa25..143f4fd52 100644 --- a/src/interfaces/IQuorumManager.sol +++ b/src/interfaces/IQuorumManager.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for QuorumManager /// @author ZeroPoint Labs interface IQuorumManager { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -34,4 +33,4 @@ interface IQuorumManager { /// @param quorum_ the minimum number of message bridges required for processing /// NOTE: overriding child contracts should handle the sender validation & setting of message quorum function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/ISuperPositions.sol b/src/interfaces/ISuperPositions.sol index d5d7914aa..1c3c8d2ea 100644 --- a/src/interfaces/ISuperPositions.sol +++ b/src/interfaces/ISuperPositions.sol @@ -8,7 +8,6 @@ import { AMBMessage } from "../types/DataTypes.sol"; /// @dev Interface for SuperPositions /// @author Zeropoint Labs interface ISuperPositions is IERC1155A { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -17,7 +16,7 @@ interface ISuperPositions is IERC1155A { uint256 txInfo; address receiverAddressSP; } - + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -98,4 +97,4 @@ interface ISuperPositions is IERC1155A { /// @dev allows to create sERC0 using broadcast state registry /// @param data_ is the crosschain payload function stateSyncBroadcast(bytes memory data_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/ISuperRBAC.sol b/src/interfaces/ISuperRBAC.sol index 5d54de9ef..98f06ceba 100644 --- a/src/interfaces/ISuperRBAC.sol +++ b/src/interfaces/ISuperRBAC.sol @@ -7,7 +7,6 @@ import { IAccessControl } from "openzeppelin-contracts/contracts/access/IAccessC /// @dev Interface for SuperRBAC /// @author Zeropoint Labs interface ISuperRBAC is IAccessControl { - ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -111,4 +110,4 @@ interface ISuperRBAC is IAccessControl { /// @dev allows sync of global roles from different chains using broadcast registry /// @notice may not work for all roles function stateSyncBroadcast(bytes memory data_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/ISuperformFactory.sol b/src/interfaces/ISuperformFactory.sol index 79c770093..ae5a47ac4 100644 --- a/src/interfaces/ISuperformFactory.sol +++ b/src/interfaces/ISuperformFactory.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for SuperformFactory /// @author ZeroPoint Labs interface ISuperformFactory { - ////////////////////////////////////////////////////////////// // CONSTANTS // ////////////////////////////////////////////////////////////// @@ -140,4 +139,4 @@ interface ISuperformFactory { ) external payable; -} \ No newline at end of file +} diff --git a/src/vendor/lifi/celer-network/MsgDataTypes.sol b/src/vendor/lifi/celer-network/MsgDataTypes.sol index 5427869e5..c3ca0a913 100644 --- a/src/vendor/lifi/celer-network/MsgDataTypes.sol +++ b/src/vendor/lifi/celer-network/MsgDataTypes.sol @@ -26,6 +26,7 @@ library MsgDataTypes { PegWithdraw, // withdraw from original token vault PegV2Mint, // mint through pegged token bridge v2 PegV2Withdraw // withdraw from original token vault v2 + } enum MsgType { @@ -39,6 +40,7 @@ library MsgDataTypes { Fail, Fallback, Pending // transient state within a transaction + } struct TransferInfo { @@ -91,4 +93,4 @@ library MsgDataTypes { address[] signers; uint256[] powers; } -} \ No newline at end of file +} diff --git a/test/unit/payments/PaymentHelper.t.sol b/test/unit/payments/PaymentHelper.t.sol index 3c9e4d87b..503aea624 100644 --- a/test/unit/payments/PaymentHelper.t.sol +++ b/test/unit/payments/PaymentHelper.t.sol @@ -569,7 +569,6 @@ contract PaymentHelperTest is ProtocolActions { assertEq(fees3, 0); } - function test_estimateSingleDirectMultiVault() public view { /// @dev scenario: single vault withdrawal @@ -1664,4 +1663,4 @@ contract PaymentHelperTest is ProtocolActions { superformId_ |= uint256(formImplementationId_) << 160; superformId_ |= uint256(chainId_) << 192; } -} \ No newline at end of file +} From fc6f31c5d18b12c1db2931e29a944418c9f321d9 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:18:51 +0100 Subject: [PATCH 25/51] fix: formatting --- .../forge-scripts/safe/lib/DelegatePrank.sol | 41 +++++++++---------- src/BaseForm.sol | 5 ++- .../extensions/AsyncStateRegistry.sol | 6 ++- src/crosschain-data/utils/QuorumManager.sol | 3 +- .../socket/SocketOneInchValidator.sol | 3 +- src/forms/ERC4626FormImplementation.sol | 6 ++- src/forms/interfaces/IERC4626Form.sol | 3 +- src/interfaces/IAsyncStateRegistry.sol | 6 ++- src/interfaces/IBaseForm.sol | 3 +- src/interfaces/IBaseRouter.sol | 3 +- .../IBroadcastAmbImplementation.sol | 3 +- src/interfaces/ICoreStateRegistry.sol | 14 +++---- src/interfaces/IDstSwapper.sol | 3 +- src/interfaces/IEmergencyQueue.sol | 3 +- src/interfaces/IPayMaster.sol | 3 +- src/interfaces/IQuorumManager.sol | 3 +- src/interfaces/ISuperPositions.sol | 5 ++- src/interfaces/ISuperRBAC.sol | 3 +- src/interfaces/ISuperformFactory.sol | 3 +- src/interfaces/ISuperformRouterPlusAsync.sol | 33 +++++++-------- .../lifi/celer-network/MsgDataTypes.sol | 4 +- 21 files changed, 87 insertions(+), 69 deletions(-) diff --git a/script/forge-scripts/safe/lib/DelegatePrank.sol b/script/forge-scripts/safe/lib/DelegatePrank.sol index 6df91ee9b..c90184618 100644 --- a/script/forge-scripts/safe/lib/DelegatePrank.sol +++ b/script/forge-scripts/safe/lib/DelegatePrank.sol @@ -20,28 +20,27 @@ import "forge-std/console.sol"; */ contract DelegatePrank is CommonBase { - Delegator delegator = makeDelegator(); - - function makeDelegator() internal returns (Delegator) { - return new Delegator(); - } - - function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { - bytes memory code = from.code; - vm.etch(from, address(delegator).code); - (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall, (to, cd, code))); - } + Delegator delegator = makeDelegator(); + function makeDelegator() internal returns (Delegator) { + return new Delegator(); + } + + function delegatePrank(address from, address to, bytes memory cd) public returns (bool success, bytes memory ret) { + bytes memory code = from.code; + vm.etch(from,address(delegator).code); + (success, ret) = from.call(abi.encodeCall(delegator.etchCodeAndDelegateCall,(to,cd,code))); + } } contract Delegator is CommonBase { - function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { - vm.etch(address(this), code); - assembly ("memory-safe") { - let result := delegatecall(gas(), dest, add(cd, 32), mload(cd), 0, 0) - returndatacopy(0, 0, returndatasize()) - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } - } + function etchCodeAndDelegateCall(address dest, bytes memory cd, bytes calldata code) external payable virtual { + vm.etch(address(this),code); + assembly ("memory-safe") { + let result := delegatecall(gas(), dest, add(cd,32), mload(cd), 0, 0) + returndatacopy(0, 0, returndatasize()) + switch result + case 0 { revert(0, returndatasize()) } + default { return(0, returndatasize()) } } -} + } +} \ No newline at end of file diff --git a/src/BaseForm.sol b/src/BaseForm.sol index 31551584b..4b5c33961 100644 --- a/src/BaseForm.sol +++ b/src/BaseForm.sol @@ -16,6 +16,7 @@ import { IERC165 } from "openzeppelin-contracts/contracts/utils/introspection/IE /// @dev Abstract contract to be inherited by different Form implementations /// @author Zeropoint Labs abstract contract BaseForm is IBaseForm, Initializable, ERC165 { + using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -253,7 +254,7 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { } /// @dev Checks if the Form implementation has the appropriate interface support - /// @param interfaceId_ is the interfaceId to check + /// @param interfaceId_ is the interfaceId to check function supportsInterface(bytes4 interfaceId_) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId_ == type(IBaseForm).interfaceId || super.supportsInterface(interfaceId_); } @@ -317,4 +318,4 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { return ISuperformFactory(factory).isFormImplementationPaused(formImplementationId_); } -} +} \ No newline at end of file diff --git a/src/crosschain-data/extensions/AsyncStateRegistry.sol b/src/crosschain-data/extensions/AsyncStateRegistry.sol index 18afd3ac0..abf2523c3 100644 --- a/src/crosschain-data/extensions/AsyncStateRegistry.sol +++ b/src/crosschain-data/extensions/AsyncStateRegistry.sol @@ -361,7 +361,9 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } /// @inheritdoc IAsyncStateRegistry - function getSyncWithdrawTxDataPayload(uint256 payloadId_) + function getSyncWithdrawTxDataPayload( + uint256 payloadId_ + ) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_) @@ -500,4 +502,4 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } } } -} +} \ No newline at end of file diff --git a/src/crosschain-data/utils/QuorumManager.sol b/src/crosschain-data/utils/QuorumManager.sol index b84e48137..a9feff3b6 100644 --- a/src/crosschain-data/utils/QuorumManager.sol +++ b/src/crosschain-data/utils/QuorumManager.sol @@ -8,6 +8,7 @@ import { Error } from "src/libraries/Error.sol"; /// @dev Quorum thresholds using in sending proofs from chain to chain /// @author ZeroPoint Labs abstract contract QuorumManager is IQuorumManager { + ////////////////////////////////////////////////////////////// // STATE VARIABLES // ////////////////////////////////////////////////////////////// @@ -33,4 +34,4 @@ abstract contract QuorumManager is IQuorumManager { /// @inheritdoc IQuorumManager function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external virtual; -} +} \ No newline at end of file diff --git a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol index 15a042f43..59ad9a407 100644 --- a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol +++ b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol @@ -9,6 +9,7 @@ import { ISocketOneInchImpl } from "src/vendor/socket/ISocketOneInchImpl.sol"; /// @dev Asserts Socket same-chain txData is valid /// @author Zeropoint Labs contract SocketOneInchValidator is BridgeValidator { + ////////////////////////////////////////////////////////////// // CONSTRUCTOR // ////////////////////////////////////////////////////////////// @@ -94,4 +95,4 @@ contract SocketOneInchValidator is BridgeValidator { function _parseCallData(bytes calldata callData) internal pure returns (bytes calldata) { return callData[4:]; } -} +} \ No newline at end of file diff --git a/src/forms/ERC4626FormImplementation.sol b/src/forms/ERC4626FormImplementation.sol index 1c50775f7..3eb1b71d1 100644 --- a/src/forms/ERC4626FormImplementation.sol +++ b/src/forms/ERC4626FormImplementation.sol @@ -16,6 +16,7 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Has common ERC4626 internal functions that can be re-used by implementations /// @author Zeropoint Labs abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { + using SafeERC20 for IERC20; using SafeERC20 for IERC4626; using DataLib for uint256; @@ -228,7 +229,7 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { /// superform data if ( vars.assetDifference * ENTIRE_SLIPPAGE - < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) + < singleVaultData_.amount * (ENTIRE_SLIPPAGE - singleVaultData_.maxSlippage) ) { revert Error.DIRECT_DEPOSIT_SWAP_FAILED(); } @@ -270,6 +271,7 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { } function _processDirectWithdraw(InitSingleVaultData memory singleVaultData_) internal returns (uint256 assets) { + DirectWithdrawLocalVars memory vars; /// @dev if there is no txData, on withdraws the receiver is receiverAddress, otherwise it @@ -490,4 +492,4 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { emit FormDustForwardedToPaymaster(token_, dust); } } -} +} \ No newline at end of file diff --git a/src/forms/interfaces/IERC4626Form.sol b/src/forms/interfaces/IERC4626Form.sol index 9891d2574..0e308027f 100644 --- a/src/forms/interfaces/IERC4626Form.sol +++ b/src/forms/interfaces/IERC4626Form.sol @@ -7,6 +7,7 @@ import { IERC20 } from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol" /// @dev Interface for ERC4626Form /// @author Zeropoint Labs interface IERC4626Form is IERC20 { + ////////////////////////////////////////////////////////////// // EXTERNAL VIEW FUNCTIONS // ////////////////////////////////////////////////////////////// @@ -38,4 +39,4 @@ interface IERC4626Form is IERC20 { function previewWithdrawFrom(uint256 assets_) external view returns (uint256); function previewRedeemFrom(uint256 shares_) external view returns (uint256); -} +} \ No newline at end of file diff --git a/src/interfaces/IAsyncStateRegistry.sol b/src/interfaces/IAsyncStateRegistry.sol index cee773fce..a091e4083 100644 --- a/src/interfaces/IAsyncStateRegistry.sol +++ b/src/interfaces/IAsyncStateRegistry.sol @@ -101,7 +101,9 @@ interface IAsyncStateRegistry { /// @notice retrieves the sync withdraw txData payload for a given payload ID /// @param payloadId_ The ID of the payload /// @return syncWithdrawTxDataPayload_ for the specified payload ID - function getSyncWithdrawTxDataPayload(uint256 payloadId_) + function getSyncWithdrawTxDataPayload( + uint256 payloadId_ + ) external view returns (SyncWithdrawTxDataPayload memory syncWithdrawTxDataPayload_); @@ -149,4 +151,4 @@ interface IAsyncStateRegistry { /// @param payloadId_ is the id of the payload to finalize /// @param txData_ is the off-chain generated transaction data function processSyncWithdrawWithUpdatedTxData(uint256 payloadId_, bytes memory txData_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/IBaseForm.sol b/src/interfaces/IBaseForm.sol index 5b380793c..f22a4d59c 100644 --- a/src/interfaces/IBaseForm.sol +++ b/src/interfaces/IBaseForm.sol @@ -9,6 +9,7 @@ import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.s /// @dev Interface for BaseForm /// @author ZeroPoint Labs interface IBaseForm is IERC165 { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -156,4 +157,4 @@ interface IBaseForm is IERC165 { /// @dev moves all dust in the contract to Paymaster contract /// @param token_ The address of the token to forward function forwardDustToPaymaster(address token_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IBaseRouter.sol b/src/interfaces/IBaseRouter.sol index 3a651f584..5f43ca51e 100644 --- a/src/interfaces/IBaseRouter.sol +++ b/src/interfaces/IBaseRouter.sol @@ -7,6 +7,7 @@ import "src/types/DataTypes.sol"; /// @dev Interface for abstract BaseRouter /// @author Zeropoint Labs interface IBaseRouter { + ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// @@ -62,4 +63,4 @@ interface IBaseRouter { /// @dev Forwards dust to Paymaster /// @param token_ the token to forward function forwardDustToPaymaster(address token_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IBroadcastAmbImplementation.sol b/src/interfaces/IBroadcastAmbImplementation.sol index 83de6ca83..1df089dd3 100644 --- a/src/interfaces/IBroadcastAmbImplementation.sol +++ b/src/interfaces/IBroadcastAmbImplementation.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for AMBs used in Broadcasting /// @author ZeroPoint Labs interface IBroadcastAmbImplementation { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -32,4 +33,4 @@ interface IBroadcastAmbImplementation { /// @param message_ is the cross-chain message to be broadcasted /// @param extraData_ is optional broadcast override information function broadcastPayload(address srcSender_, bytes memory message_, bytes memory extraData_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/ICoreStateRegistry.sol b/src/interfaces/ICoreStateRegistry.sol index a9775e171..f6cee7669 100644 --- a/src/interfaces/ICoreStateRegistry.sol +++ b/src/interfaces/ICoreStateRegistry.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for CoreStateRegistry /// @author ZeroPoint Labs interface ICoreStateRegistry { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -33,7 +34,10 @@ interface ICoreStateRegistry { /// @dev is emitted when a rescue is proposed for failed deposits in a payload event RescueProposed( - uint256 indexed payloadId, uint256[] superformIds, uint256[] proposedAmount, uint256 proposedTime + uint256 indexed payloadId, + uint256[] superformIds, + uint256[] proposedAmount, + uint256 proposedTime ); /// @dev is emitted when an user disputed his refund amounts @@ -60,11 +64,7 @@ interface ICoreStateRegistry { /// @param finalAmount_ is the final amount of tokens received /// @param amount_ is the indicated amount of tokens to be received /// @param maxSlippage_ is the amount of acceptable slippage for the transaction - function validateSlippage( - uint256 finalAmount_, - uint256 amount_, - uint256 maxSlippage_ - ) + function validateSlippage(uint256 finalAmount_, uint256 amount_, uint256 maxSlippage_) external view returns (bool); @@ -103,4 +103,4 @@ interface ICoreStateRegistry { /// @dev allows anyone to settle refunds for unprocessed/failed deposits past the challenge period /// @param payloadId_ is the identifier of the cross-chain payload function finalizeRescueFailedDeposits(uint256 payloadId_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IDstSwapper.sol b/src/interfaces/IDstSwapper.sol index fefd11f97..ef7b254e1 100644 --- a/src/interfaces/IDstSwapper.sol +++ b/src/interfaces/IDstSwapper.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for DstSwapper /// @author Zeropoint Labs interface IDstSwapper { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -101,4 +102,4 @@ interface IDstSwapper { /// @param interimToken_ is the refund token /// @param amount_ is the refund amount function processFailedTx(address user_, address interimToken_, uint256 amount_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IEmergencyQueue.sol b/src/interfaces/IEmergencyQueue.sol index 8dcd2dd15..ac8ba2767 100644 --- a/src/interfaces/IEmergencyQueue.sol +++ b/src/interfaces/IEmergencyQueue.sol @@ -7,6 +7,7 @@ import { InitSingleVaultData } from "src/types/DataTypes.sol"; /// @dev Interface for EmergencyQueue /// @author ZeroPoint Labs interface IEmergencyQueue { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -47,4 +48,4 @@ interface IEmergencyQueue { /// @dev called by emergency admin to batch process queued withdrawals /// @param ids_ is the array of identifiers of the queued actions function batchExecuteQueuedWithdrawal(uint256[] memory ids_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/IPayMaster.sol b/src/interfaces/IPayMaster.sol index 8f7689dbe..c78878ac3 100644 --- a/src/interfaces/IPayMaster.sol +++ b/src/interfaces/IPayMaster.sol @@ -7,6 +7,7 @@ import { LiqRequest } from "src/types/DataTypes.sol"; /// @dev Interface for PayMaster /// @author ZeroPoint Labs interface IPayMaster { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -50,4 +51,4 @@ interface IPayMaster { /// @dev accepts payment from user /// @param user_ is the wallet address of the paying user function makePayment(address user_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/IQuorumManager.sol b/src/interfaces/IQuorumManager.sol index 143f4fd52..b85bdaa25 100644 --- a/src/interfaces/IQuorumManager.sol +++ b/src/interfaces/IQuorumManager.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for QuorumManager /// @author ZeroPoint Labs interface IQuorumManager { + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -33,4 +34,4 @@ interface IQuorumManager { /// @param quorum_ the minimum number of message bridges required for processing /// NOTE: overriding child contracts should handle the sender validation & setting of message quorum function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperPositions.sol b/src/interfaces/ISuperPositions.sol index 1c3c8d2ea..d5d7914aa 100644 --- a/src/interfaces/ISuperPositions.sol +++ b/src/interfaces/ISuperPositions.sol @@ -8,6 +8,7 @@ import { AMBMessage } from "../types/DataTypes.sol"; /// @dev Interface for SuperPositions /// @author Zeropoint Labs interface ISuperPositions is IERC1155A { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -16,7 +17,7 @@ interface ISuperPositions is IERC1155A { uint256 txInfo; address receiverAddressSP; } - + ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -97,4 +98,4 @@ interface ISuperPositions is IERC1155A { /// @dev allows to create sERC0 using broadcast state registry /// @param data_ is the crosschain payload function stateSyncBroadcast(bytes memory data_) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperRBAC.sol b/src/interfaces/ISuperRBAC.sol index 98f06ceba..5d54de9ef 100644 --- a/src/interfaces/ISuperRBAC.sol +++ b/src/interfaces/ISuperRBAC.sol @@ -7,6 +7,7 @@ import { IAccessControl } from "openzeppelin-contracts/contracts/access/IAccessC /// @dev Interface for SuperRBAC /// @author Zeropoint Labs interface ISuperRBAC is IAccessControl { + ////////////////////////////////////////////////////////////// // STRUCTS // ////////////////////////////////////////////////////////////// @@ -110,4 +111,4 @@ interface ISuperRBAC is IAccessControl { /// @dev allows sync of global roles from different chains using broadcast registry /// @notice may not work for all roles function stateSyncBroadcast(bytes memory data_) external; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperformFactory.sol b/src/interfaces/ISuperformFactory.sol index ae5a47ac4..79c770093 100644 --- a/src/interfaces/ISuperformFactory.sol +++ b/src/interfaces/ISuperformFactory.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.23; /// @dev Interface for SuperformFactory /// @author ZeroPoint Labs interface ISuperformFactory { + ////////////////////////////////////////////////////////////// // CONSTANTS // ////////////////////////////////////////////////////////////// @@ -139,4 +140,4 @@ interface ISuperformFactory { ) external payable; -} +} \ No newline at end of file diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 4d989466a..94842aac4 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -18,9 +18,6 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown if the caller is not router plus error NOT_ROUTER_PLUS(); - /// @notice thrown if the caller is not core state registry rescuer - error NOT_CORE_STATE_REGISTRY_RESCUER(); - /// @notice thrown if the rebalance to update is invalid error COMPLETE_REBALANCE_INVALID_TX_DATA_UPDATE(); @@ -47,17 +44,17 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown to avoid processing the same rebalance payload twice error REBALANCE_ALREADY_PROCESSED(); - /// @notice thrown when the refund requester is not the payload receiver - error INVALID_REQUESTER(); + /// @notice thrown when the refund proposer is invalid + error INVALID_PROPOSER(); /// @notice thrown when the refund payload is invalid error INVALID_REFUND_DATA(); - /// @notice thrown when requestedrefund amount exceeds received amount - error REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); + /// @notice thrown when refund is already proposed + error REFUND_ALREADY_PROPOSED(); - /// @notice thrown when the refund payload is already approved - error REFUND_ALREADY_APPROVED(); + /// @notice thrown if the refund is still in dispute phase + error IN_DISPUTE_PHASE(); ////////////////////////////////////////////////////////////// // EVENTS // @@ -171,12 +168,16 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { payable returns (bool rebalanceSuccessful); - /// @notice allows the user to request a refund for the rebalance - /// @param requestedAmount_ the amount to be refunded - function requestRefund(uint256 requestedAmount_, uint256 routerplusPayloadId_) external; + /// @notice allows the receiver / disputer to protect against malicious processors + /// @param finalPayloadId_ is the unique identifier of the refund + function disputeRefund(uint256 finalPayloadId_) external; + + /// @notice allows the rescuer to propose a new refund amount after a successful dispute + /// @param finalPayloadId_ is the unique identifier of the refund + /// @param refundAmount_ is the new refund amount proposed + function proposeRefund(uint256 finalPayloadId_, uint256 refundAmount_) external; - /// @dev only callable by core state registry rescuer - /// @notice approves a refund for the rebalance and sends funds to the receiver - /// @param routerplusPayloadId_ the router plus payload id - function approveRefund(uint256 routerplusPayloadId_) external; + /// @notice allows the user to claim their refund post the dispute period + /// @param finalPayloadId_ is the unique identifier of the refund + function finalizeRefund(uint256 finalPayloadId_) external; } diff --git a/src/vendor/lifi/celer-network/MsgDataTypes.sol b/src/vendor/lifi/celer-network/MsgDataTypes.sol index c3ca0a913..5427869e5 100644 --- a/src/vendor/lifi/celer-network/MsgDataTypes.sol +++ b/src/vendor/lifi/celer-network/MsgDataTypes.sol @@ -26,7 +26,6 @@ library MsgDataTypes { PegWithdraw, // withdraw from original token vault PegV2Mint, // mint through pegged token bridge v2 PegV2Withdraw // withdraw from original token vault v2 - } enum MsgType { @@ -40,7 +39,6 @@ library MsgDataTypes { Fail, Fallback, Pending // transient state within a transaction - } struct TransferInfo { @@ -93,4 +91,4 @@ library MsgDataTypes { address[] signers; uint256[] powers; } -} +} \ No newline at end of file From 477fb323de43abd4b43b44e27d7fefbfba709e78 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:34:27 +0100 Subject: [PATCH 26/51] fix: correct interface of async router plus --- src/interfaces/ISuperformRouterPlusAsync.sol | 35 ++++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 94842aac4..99d1b3fb5 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -18,6 +18,9 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown if the caller is not router plus error NOT_ROUTER_PLUS(); + /// @notice thrown if the caller is not core state registry rescuer + error NOT_CORE_STATE_REGISTRY_RESCUER(); + /// @notice thrown if the rebalance to update is invalid error COMPLETE_REBALANCE_INVALID_TX_DATA_UPDATE(); @@ -44,17 +47,17 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown to avoid processing the same rebalance payload twice error REBALANCE_ALREADY_PROCESSED(); - /// @notice thrown when the refund proposer is invalid - error INVALID_PROPOSER(); + /// @notice thrown when the refund requester is not the payload receiver + error INVALID_REQUESTER(); /// @notice thrown when the refund payload is invalid error INVALID_REFUND_DATA(); - /// @notice thrown when refund is already proposed - error REFUND_ALREADY_PROPOSED(); + /// @notice thrown when requestedrefund amount exceeds received amount + error REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); - /// @notice thrown if the refund is still in dispute phase - error IN_DISPUTE_PHASE(); + /// @notice thrown when the refund payload is already approved + error REFUND_ALREADY_APPROVED(); ////////////////////////////////////////////////////////////// // EVENTS // @@ -168,16 +171,12 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { payable returns (bool rebalanceSuccessful); - /// @notice allows the receiver / disputer to protect against malicious processors - /// @param finalPayloadId_ is the unique identifier of the refund - function disputeRefund(uint256 finalPayloadId_) external; - - /// @notice allows the rescuer to propose a new refund amount after a successful dispute - /// @param finalPayloadId_ is the unique identifier of the refund - /// @param refundAmount_ is the new refund amount proposed - function proposeRefund(uint256 finalPayloadId_, uint256 refundAmount_) external; + /// @notice allows the user to request a refund for the rebalance + /// @param requestedAmount_ the amount to be refunded + function requestRefund(uint256 requestedAmount_, uint256 routerplusPayloadId_) external; - /// @notice allows the user to claim their refund post the dispute period - /// @param finalPayloadId_ is the unique identifier of the refund - function finalizeRefund(uint256 finalPayloadId_) external; -} + /// @dev only callable by core state registry rescuer + /// @notice approves a refund for the rebalance and sends funds to the receiver + /// @param routerplusPayloadId_ the router plus payload id + function approveRefund(uint256 routerplusPayloadId_) external; +} \ No newline at end of file From 6fda94619ac09c8b607246fdf0e4152b353544ca Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:35:06 +0200 Subject: [PATCH 27/51] refactor: rm proposedTime from Refund struct --- src/interfaces/ISuperformRouterPlusAsync.sol | 1 - src/router-plus/SuperformRouterPlusAsync.sol | 2 +- test/unit/router-plus/SuperformRouterPlus.t.sol | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 4d989466a..d16666bb5 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -100,7 +100,6 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { address receiver; address interimToken; uint256 amount; - uint256 proposedTime; } struct DecodedRouterPlusRebalanceCallData { diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 63b110330..a9f7a1243 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -264,7 +264,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou < ((data.expectedAmountInterimAsset * (ENTIRE_SLIPPAGE - data.slippage))) ) { refunds[args_.routerPlusPayloadId] = - Refund(args_.receiverAddressSP, data.interimAsset, args_.amountReceivedInterimAsset, block.timestamp); + Refund(args_.receiverAddressSP, data.interimAsset, args_.amountReceivedInterimAsset); emit RefundInitiated( args_.routerPlusPayloadId, args_.receiverAddressSP, data.interimAsset, args_.amountReceivedInterimAsset diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 59a494047..f3e5ac142 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1730,7 +1730,7 @@ contract SuperformRouterPlusTest is ProtocolActions { SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); vm.stopPrank(); - (, address refundToken,,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + (, address refundToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); /// @dev testing valid refund approval From 4e9e1048f846b46be91ae300b5b943d5d0a0cad1 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:50:21 +0100 Subject: [PATCH 28/51] fix: delegate prank --- script/forge-scripts/safe/lib/DelegatePrank.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/forge-scripts/safe/lib/DelegatePrank.sol b/script/forge-scripts/safe/lib/DelegatePrank.sol index c90184618..0e4b67557 100644 --- a/script/forge-scripts/safe/lib/DelegatePrank.sol +++ b/script/forge-scripts/safe/lib/DelegatePrank.sol @@ -43,4 +43,4 @@ contract Delegator is CommonBase { default { return(0, returndatasize()) } } } -} \ No newline at end of file +} From aa52182f86c77abccdcb406ef777287dc5f43f1d Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:53:14 +0100 Subject: [PATCH 29/51] fix: remainder of files --- src/BaseForm.sol | 2 +- src/crosschain-data/extensions/AsyncStateRegistry.sol | 2 +- src/crosschain-data/utils/QuorumManager.sol | 2 +- src/crosschain-liquidity/socket/SocketOneInchValidator.sol | 2 +- src/forms/ERC4626FormImplementation.sol | 2 +- src/forms/interfaces/IERC4626Form.sol | 2 +- src/interfaces/IAsyncStateRegistry.sol | 2 +- src/interfaces/IBaseForm.sol | 2 +- src/interfaces/IBaseRouter.sol | 2 +- src/interfaces/IBroadcastAmbImplementation.sol | 2 +- src/interfaces/ICoreStateRegistry.sol | 2 +- src/interfaces/IDstSwapper.sol | 2 +- src/interfaces/IEmergencyQueue.sol | 2 +- src/interfaces/IPayMaster.sol | 2 +- src/interfaces/IQuorumManager.sol | 2 +- src/interfaces/ISuperPositions.sol | 2 +- src/interfaces/ISuperRBAC.sol | 2 +- src/interfaces/ISuperformFactory.sol | 2 +- src/vendor/lifi/celer-network/MsgDataTypes.sol | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/BaseForm.sol b/src/BaseForm.sol index 4b5c33961..750915233 100644 --- a/src/BaseForm.sol +++ b/src/BaseForm.sol @@ -318,4 +318,4 @@ abstract contract BaseForm is IBaseForm, Initializable, ERC165 { return ISuperformFactory(factory).isFormImplementationPaused(formImplementationId_); } -} \ No newline at end of file +} diff --git a/src/crosschain-data/extensions/AsyncStateRegistry.sol b/src/crosschain-data/extensions/AsyncStateRegistry.sol index abf2523c3..37bc93d53 100644 --- a/src/crosschain-data/extensions/AsyncStateRegistry.sol +++ b/src/crosschain-data/extensions/AsyncStateRegistry.sol @@ -502,4 +502,4 @@ contract AsyncStateRegistry is BaseStateRegistry, IAsyncStateRegistry { } } } -} \ No newline at end of file +} diff --git a/src/crosschain-data/utils/QuorumManager.sol b/src/crosschain-data/utils/QuorumManager.sol index a9feff3b6..42c596e15 100644 --- a/src/crosschain-data/utils/QuorumManager.sol +++ b/src/crosschain-data/utils/QuorumManager.sol @@ -34,4 +34,4 @@ abstract contract QuorumManager is IQuorumManager { /// @inheritdoc IQuorumManager function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external virtual; -} \ No newline at end of file +} diff --git a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol index 59ad9a407..e4b55a2d6 100644 --- a/src/crosschain-liquidity/socket/SocketOneInchValidator.sol +++ b/src/crosschain-liquidity/socket/SocketOneInchValidator.sol @@ -95,4 +95,4 @@ contract SocketOneInchValidator is BridgeValidator { function _parseCallData(bytes calldata callData) internal pure returns (bytes calldata) { return callData[4:]; } -} \ No newline at end of file +} diff --git a/src/forms/ERC4626FormImplementation.sol b/src/forms/ERC4626FormImplementation.sol index 3eb1b71d1..0d563a171 100644 --- a/src/forms/ERC4626FormImplementation.sol +++ b/src/forms/ERC4626FormImplementation.sol @@ -492,4 +492,4 @@ abstract contract ERC4626FormImplementation is BaseForm, LiquidityHandler { emit FormDustForwardedToPaymaster(token_, dust); } } -} \ No newline at end of file +} diff --git a/src/forms/interfaces/IERC4626Form.sol b/src/forms/interfaces/IERC4626Form.sol index 0e308027f..14cb791f1 100644 --- a/src/forms/interfaces/IERC4626Form.sol +++ b/src/forms/interfaces/IERC4626Form.sol @@ -39,4 +39,4 @@ interface IERC4626Form is IERC20 { function previewWithdrawFrom(uint256 assets_) external view returns (uint256); function previewRedeemFrom(uint256 shares_) external view returns (uint256); -} \ No newline at end of file +} diff --git a/src/interfaces/IAsyncStateRegistry.sol b/src/interfaces/IAsyncStateRegistry.sol index a091e4083..c47f56881 100644 --- a/src/interfaces/IAsyncStateRegistry.sol +++ b/src/interfaces/IAsyncStateRegistry.sol @@ -151,4 +151,4 @@ interface IAsyncStateRegistry { /// @param payloadId_ is the id of the payload to finalize /// @param txData_ is the off-chain generated transaction data function processSyncWithdrawWithUpdatedTxData(uint256 payloadId_, bytes memory txData_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/IBaseForm.sol b/src/interfaces/IBaseForm.sol index f22a4d59c..4a298a947 100644 --- a/src/interfaces/IBaseForm.sol +++ b/src/interfaces/IBaseForm.sol @@ -157,4 +157,4 @@ interface IBaseForm is IERC165 { /// @dev moves all dust in the contract to Paymaster contract /// @param token_ The address of the token to forward function forwardDustToPaymaster(address token_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IBaseRouter.sol b/src/interfaces/IBaseRouter.sol index 5f43ca51e..7679081b7 100644 --- a/src/interfaces/IBaseRouter.sol +++ b/src/interfaces/IBaseRouter.sol @@ -63,4 +63,4 @@ interface IBaseRouter { /// @dev Forwards dust to Paymaster /// @param token_ the token to forward function forwardDustToPaymaster(address token_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IBroadcastAmbImplementation.sol b/src/interfaces/IBroadcastAmbImplementation.sol index 1df089dd3..545c045bf 100644 --- a/src/interfaces/IBroadcastAmbImplementation.sol +++ b/src/interfaces/IBroadcastAmbImplementation.sol @@ -33,4 +33,4 @@ interface IBroadcastAmbImplementation { /// @param message_ is the cross-chain message to be broadcasted /// @param extraData_ is optional broadcast override information function broadcastPayload(address srcSender_, bytes memory message_, bytes memory extraData_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/ICoreStateRegistry.sol b/src/interfaces/ICoreStateRegistry.sol index f6cee7669..953130499 100644 --- a/src/interfaces/ICoreStateRegistry.sol +++ b/src/interfaces/ICoreStateRegistry.sol @@ -103,4 +103,4 @@ interface ICoreStateRegistry { /// @dev allows anyone to settle refunds for unprocessed/failed deposits past the challenge period /// @param payloadId_ is the identifier of the cross-chain payload function finalizeRescueFailedDeposits(uint256 payloadId_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IDstSwapper.sol b/src/interfaces/IDstSwapper.sol index ef7b254e1..62bad9b90 100644 --- a/src/interfaces/IDstSwapper.sol +++ b/src/interfaces/IDstSwapper.sol @@ -102,4 +102,4 @@ interface IDstSwapper { /// @param interimToken_ is the refund token /// @param amount_ is the refund amount function processFailedTx(address user_, address interimToken_, uint256 amount_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IEmergencyQueue.sol b/src/interfaces/IEmergencyQueue.sol index ac8ba2767..5d2daa982 100644 --- a/src/interfaces/IEmergencyQueue.sol +++ b/src/interfaces/IEmergencyQueue.sol @@ -48,4 +48,4 @@ interface IEmergencyQueue { /// @dev called by emergency admin to batch process queued withdrawals /// @param ids_ is the array of identifiers of the queued actions function batchExecuteQueuedWithdrawal(uint256[] memory ids_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/IPayMaster.sol b/src/interfaces/IPayMaster.sol index c78878ac3..50448e658 100644 --- a/src/interfaces/IPayMaster.sol +++ b/src/interfaces/IPayMaster.sol @@ -51,4 +51,4 @@ interface IPayMaster { /// @dev accepts payment from user /// @param user_ is the wallet address of the paying user function makePayment(address user_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/IQuorumManager.sol b/src/interfaces/IQuorumManager.sol index b85bdaa25..813d1d0e2 100644 --- a/src/interfaces/IQuorumManager.sol +++ b/src/interfaces/IQuorumManager.sol @@ -34,4 +34,4 @@ interface IQuorumManager { /// @param quorum_ the minimum number of message bridges required for processing /// NOTE: overriding child contracts should handle the sender validation & setting of message quorum function setRequiredMessagingQuorum(uint64 srcChainId_, uint256 quorum_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/ISuperPositions.sol b/src/interfaces/ISuperPositions.sol index d5d7914aa..1f1dd069a 100644 --- a/src/interfaces/ISuperPositions.sol +++ b/src/interfaces/ISuperPositions.sol @@ -98,4 +98,4 @@ interface ISuperPositions is IERC1155A { /// @dev allows to create sERC0 using broadcast state registry /// @param data_ is the crosschain payload function stateSyncBroadcast(bytes memory data_) external payable; -} \ No newline at end of file +} diff --git a/src/interfaces/ISuperRBAC.sol b/src/interfaces/ISuperRBAC.sol index 5d54de9ef..3b9a6abb1 100644 --- a/src/interfaces/ISuperRBAC.sol +++ b/src/interfaces/ISuperRBAC.sol @@ -111,4 +111,4 @@ interface ISuperRBAC is IAccessControl { /// @dev allows sync of global roles from different chains using broadcast registry /// @notice may not work for all roles function stateSyncBroadcast(bytes memory data_) external; -} \ No newline at end of file +} diff --git a/src/interfaces/ISuperformFactory.sol b/src/interfaces/ISuperformFactory.sol index 79c770093..dc1705e80 100644 --- a/src/interfaces/ISuperformFactory.sol +++ b/src/interfaces/ISuperformFactory.sol @@ -140,4 +140,4 @@ interface ISuperformFactory { ) external payable; -} \ No newline at end of file +} diff --git a/src/vendor/lifi/celer-network/MsgDataTypes.sol b/src/vendor/lifi/celer-network/MsgDataTypes.sol index 5427869e5..7a63d0ac6 100644 --- a/src/vendor/lifi/celer-network/MsgDataTypes.sol +++ b/src/vendor/lifi/celer-network/MsgDataTypes.sol @@ -91,4 +91,4 @@ library MsgDataTypes { address[] signers; uint256[] powers; } -} \ No newline at end of file +} From b6ce0b75f1ac6b9113b486fb3b99efb4fe54ab3f Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:04:51 +0100 Subject: [PATCH 30/51] test: fix staging test --- test/mainnet/SmokeTest.Staging.t.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/mainnet/SmokeTest.Staging.t.sol b/test/mainnet/SmokeTest.Staging.t.sol index f97a3095c..45851cfca 100644 --- a/test/mainnet/SmokeTest.Staging.t.sol +++ b/test/mainnet/SmokeTest.Staging.t.sol @@ -555,15 +555,13 @@ contract SmokeTestStaging is MainnetBaseSetup { for (uint256 i; i < TARGET_DEPLOYMENT_CHAINS.length; ++i) { uint64 chainId = TARGET_DEPLOYMENT_CHAINS[i]; - vm.selectFork(FORKS[chainId]); superFactory = SuperformFactory(getContract(chainId, "SuperformFactory")); chainId != BLAST ? assertEq(superFactory.getFormImplementation(5), getContract(chainId, "ERC5115Form")) : assertEq(superFactory.getFormImplementation(205), getContract(chainId, "ERC5115Form")); - /// @dev in blast there are 6 forms (2 without operator, 2 with wrong state registry and 2 right superforms) - assertEq(superFactory.getFormCount(), chainId == LINEA ? 3 : chainId == BLAST ? 6 : 5); + assertEq(superFactory.getFormCount(), chainId == LINEA ? 5 : chainId == BLAST ? 8 : 7); assertEq(superFactory.getFormStateRegistryId(5), 1); } } From 19878b6053e43160a088a14f6a53329ae1ec9730 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:04:19 +0200 Subject: [PATCH 31/51] refactor: rename RefundRequested event --- src/interfaces/ISuperformRouterPlusAsync.sol | 4 ++-- src/router-plus/SuperformRouterPlusAsync.sol | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index d16666bb5..9736842e4 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -68,12 +68,12 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @param routerPlusPayloadId The router plus payload id of the rebalance event XChainRebalanceComplete(address indexed receiver, uint256 indexed routerPlusPayloadId); - /// @notice emitted when a new refund is created + /// @notice emitted when a new refund is proposed /// @param routerPlusPayloadId is the unique identifier for the payload /// @param refundReceiver is the address of the user who'll receiver the refund /// @param refundToken is the token to be refunded /// @param refundAmount is the new refund amount - event RefundInitiated( + event RefundRequested( uint256 indexed routerPlusPayloadId, address indexed refundReceiver, address refundToken, uint256 refundAmount ); diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index a9f7a1243..e632aec6c 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -434,7 +434,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou r.amount = requestedAmount_; - emit RefundInitiated( + emit RefundRequested( routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_ ); } From b89ec5a7c5d535f29deb242bcf90343ebeded3a7 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:07:06 +0200 Subject: [PATCH 32/51] refactor: rename RefundRequested event --- src/interfaces/ISuperformRouterPlusAsync.sol | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 9736842e4..615b9a15a 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -68,12 +68,21 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @param routerPlusPayloadId The router plus payload id of the rebalance event XChainRebalanceComplete(address indexed receiver, uint256 indexed routerPlusPayloadId); - /// @notice emitted when a new refund is proposed + /// @notice emitted when a new refund is created /// @param routerPlusPayloadId is the unique identifier for the payload /// @param refundReceiver is the address of the user who'll receiver the refund /// @param refundToken is the token to be refunded /// @param refundAmount is the new refund amount - event RefundRequested( + event RefundInitiated( + uint256 indexed routerPlusPayloadId, address indexed refundReceiver, address refundToken, uint256 refundAmount + ); + + /// @notice emitted when a refund is proposed + /// @param routerPlusPayloadId is the unique identifier for the payload + /// @param refundReceiver is the address of the user who'll receiver the refund + /// @param refundToken is the token to be refunded + /// @param refundAmount is the new refund amount + event refundRequested( uint256 indexed routerPlusPayloadId, address indexed refundReceiver, address refundToken, uint256 refundAmount ); From d6541b05875c1c0cc8310cd96676e690aa395136 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:01:33 +0200 Subject: [PATCH 33/51] fix: typo --- src/router-plus/SuperformRouterPlusAsync.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index e632aec6c..5e31cd814 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -434,7 +434,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou r.amount = requestedAmount_; - emit RefundRequested( + emit refundRequested( routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_ ); } From 62dd458c07e76657112ab2f52631525b130fbd04 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:51:42 +0200 Subject: [PATCH 34/51] fix: update tests --- .../router-plus/SuperformRouterPlus.t.sol | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index f3e5ac142..b7ec0ccaa 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1703,17 +1703,12 @@ contract SuperformRouterPlusTest is ProtocolActions { /// @dev testing invalid requester vm.startPrank(address(222)); vm.expectRevert(ISuperformRouterPlusAsync.INVALID_REQUESTER.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(completeArgs.amountReceivedInterimAsset, 1); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1); vm.stopPrank(); - /// @dev testing zero input value - vm.startPrank(deployer); - vm.expectRevert(Error.ZERO_INPUT_VALUE.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(0, 1); - /// @dev testing valid refund request - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(completeArgs.amountReceivedInterimAsset, 1); - vm.stopPrank(); + //SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1000); + //vm.stopPrank(); // Step 6: Approve refund @@ -1724,11 +1719,11 @@ contract SuperformRouterPlusTest is ProtocolActions { vm.stopPrank(); /// @dev testing refund amount exceeds expected amount - vm.startPrank(deployer); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(100, 1); - vm.expectRevert(ISuperformRouterPlusAsync.REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); - vm.stopPrank(); + // vm.startPrank(deployer); + // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1); + // vm.expectRevert(ISuperformRouterPlusAsync.REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT.selector); + // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); + // vm.stopPrank(); (, address refundToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); From 8d38ebd3b7790097067beb1841f22f001797f1ca Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:52:04 +0200 Subject: [PATCH 35/51] refactor: rm amount from requestRefund() --- src/router-plus/SuperformRouterPlusAsync.sol | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 5e31cd814..06c14a442 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -425,17 +425,20 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou } /// @inheritdoc ISuperformRouterPlusAsync - function requestRefund(uint256 requestedAmount_, uint256 routerPlusPayloadId_) external { + function requestRefund(uint256 routerPlusPayloadId_) external { Refund memory r = refunds[routerPlusPayloadId_]; if (msg.sender != r.receiver) revert INVALID_REQUESTER(); - if (requestedAmount_ == 0) revert Error.ZERO_INPUT_VALUE(); if (r.interimToken == address(0)) revert INVALID_REFUND_DATA(); - r.amount = requestedAmount_; + XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; + + uint256 amountToRefund = data.expectedAmountInterimAsset; + + r.amount = amountToRefund; emit refundRequested( - routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount_ + routerPlusPayloadId_, msg.sender, r.interimToken, r.amount ); } @@ -445,9 +448,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou Refund memory r = refunds[routerPlusPayloadId_]; - XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; - - if (data.expectedAmountInterimAsset < r.amount) revert REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); + if (r.amount == 0) revert INVALID_REFUND_DATA(); approvedRefund[routerPlusPayloadId_] = true; From b85030d9cad76dd35a1ff8f392a3ec76b3dc96b0 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:52:08 +0200 Subject: [PATCH 36/51] refactor: rm amount from requestRefund() --- src/interfaces/ISuperformRouterPlusAsync.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 615b9a15a..684793f83 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -180,8 +180,8 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { returns (bool rebalanceSuccessful); /// @notice allows the user to request a refund for the rebalance - /// @param requestedAmount_ the amount to be refunded - function requestRefund(uint256 requestedAmount_, uint256 routerplusPayloadId_) external; + /// @param routerplusPayloadId_ the router plus payload id + function requestRefund(uint256 routerplusPayloadId_) external; /// @dev only callable by core state registry rescuer /// @notice approves a refund for the rebalance and sends funds to the receiver From 186182d47fe280414142c34f5d755cb2ed5ca07a Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 08:28:53 +0200 Subject: [PATCH 37/51] fix: reorder test logic --- .../adapters/HyperlaneImplementation.t.sol | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/fuzz/crosschain-data/adapters/HyperlaneImplementation.t.sol b/test/fuzz/crosschain-data/adapters/HyperlaneImplementation.t.sol index 0558f08bd..9d5eb1436 100644 --- a/test/fuzz/crosschain-data/adapters/HyperlaneImplementation.t.sol +++ b/test/fuzz/crosschain-data/adapters/HyperlaneImplementation.t.sol @@ -107,21 +107,23 @@ contract HyperlaneImplementationTest is CommonProtocolActions { vm.startPrank(deployer); uint256 userIndex = userSeed_ % users.length; + + vm.assume(malice_ != getContract(ETH, "CoreStateRegistry")); + vm.assume(malice_ != getContract(ETH, "TimelockStateRegistry")); + vm.assume(malice_ != getContract(ETH, "BroadcastRegistry")); + vm.assume(malice_ != getContract(ETH, "AsyncStateRegistry")); + AMBMessage memory ambMessage; BroadCastAMBExtraData memory ambExtraData; address coreStateRegistry; (ambMessage, ambExtraData, coreStateRegistry) = setupBroadcastPayloadAMBData(users[userIndex], address(hyperlaneImplementation)); - - vm.expectRevert(Error.NOT_STATE_REGISTRY.selector); - vm.assume(malice_ != getContract(ETH, "CoreStateRegistry")); - vm.assume(malice_ != getContract(ETH, "TimelockStateRegistry")); - vm.assume(malice_ != getContract(ETH, "BroadcastRegistry")); - vm.assume(malice_ != getContract(ETH, "AsyncStateRegistry")); + vm.stopPrank(); vm.deal(malice_, 100 ether); vm.prank(malice_); + vm.expectRevert(Error.NOT_STATE_REGISTRY.selector); hyperlaneImplementation.dispatchPayload{ value: 0.1 ether }( users[userIndex], chainIds[5], abi.encode(ambMessage), abi.encode(ambExtraData) ); From af8d01b1dc1dc37265ab764f0aa9fb94cef5bdb3 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:41:17 +0200 Subject: [PATCH 38/51] add check for expectedAmountInterimAsset == 0 in completeCrossCHainRebalance() --- src/router-plus/SuperformRouterPlusAsync.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 06c14a442..7a767062d 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -249,6 +249,10 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou revert Error.INSUFFICIENT_BALANCE(); } + if (data.expectedAmountInterimAsset == 0) { + revert Error.ZERO_AMOUNT(); + } + /// @dev We don't allow negative slippage (and funds are not rescued) /// @notice This means that a keeper has to re-submit a completeCrossChainRebalance call /// @notice With an amount received lower than expected From a548dbaa86ab8b968f85c32ec5a6cd7ad065853b Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:28:25 +0100 Subject: [PATCH 39/51] fix: simplify request amount to refund --- src/router-plus/SuperformRouterPlusAsync.sol | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 7a767062d..4a37e1d0a 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -267,8 +267,8 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou ENTIRE_SLIPPAGE * args_.amountReceivedInterimAsset < ((data.expectedAmountInterimAsset * (ENTIRE_SLIPPAGE - data.slippage))) ) { - refunds[args_.routerPlusPayloadId] = - Refund(args_.receiverAddressSP, data.interimAsset, args_.amountReceivedInterimAsset); + + refunds[args_.routerPlusPayloadId] = Refund(args_.receiverAddressSP, data.interimAsset); emit RefundInitiated( args_.routerPlusPayloadId, args_.receiverAddressSP, data.interimAsset, args_.amountReceivedInterimAsset @@ -429,7 +429,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou } /// @inheritdoc ISuperformRouterPlusAsync - function requestRefund(uint256 routerPlusPayloadId_) external { + function requestRefund(uint256 routerPlusPayloadId_, uint256 requestedAmount) external { Refund memory r = refunds[routerPlusPayloadId_]; if (msg.sender != r.receiver) revert INVALID_REQUESTER(); @@ -437,19 +437,21 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou XChainRebalanceData memory data = xChainRebalanceCallData[r.receiver][routerPlusPayloadId_]; - uint256 amountToRefund = data.expectedAmountInterimAsset; + if (requestedAmount > data.expectedAmountInterimAsset) { + revert REQUESTED_AMOUNT_TOO_HIGH(); + } + + uint256 amountToRefund = requestedAmount; r.amount = amountToRefund; - emit refundRequested( - routerPlusPayloadId_, msg.sender, r.interimToken, r.amount - ); + emit refundRequested(routerPlusPayloadId_, msg.sender, r.interimToken, r.amount); } /// @inheritdoc ISuperformRouterPlusAsync function approveRefund(uint256 routerPlusPayloadId_) external onlyCoreStateRegistryRescuer { if (approvedRefund[routerPlusPayloadId_]) revert REFUND_ALREADY_APPROVED(); - + Refund memory r = refunds[routerPlusPayloadId_]; if (r.amount == 0) revert INVALID_REFUND_DATA(); From 5c246e4f54038bfee58496d09635a05c84fd129d Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:02:31 +0200 Subject: [PATCH 40/51] refactor: update refund mechanism --- src/interfaces/ISuperformRouterPlusAsync.sol | 6 +++--- src/router-plus/SuperformRouterPlusAsync.sol | 10 +++------- test/unit/router-plus/SuperformRouterPlus.t.sol | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/interfaces/ISuperformRouterPlusAsync.sol b/src/interfaces/ISuperformRouterPlusAsync.sol index 8aca521a0..fe9f7bc5e 100644 --- a/src/interfaces/ISuperformRouterPlusAsync.sol +++ b/src/interfaces/ISuperformRouterPlusAsync.sol @@ -53,8 +53,8 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice thrown when the refund payload is invalid error INVALID_REFUND_DATA(); - /// @notice thrown when requestedrefund amount exceeds received amount - error REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT(); + /// @notice thrown when requested refund amount is too high + error REQUESTED_AMOUNT_TOO_HIGH(); /// @notice thrown when the refund payload is already approved error REFUND_ALREADY_APPROVED(); @@ -181,7 +181,7 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus { /// @notice allows the user to request a refund for the rebalance /// @param routerplusPayloadId_ the router plus payload id - function requestRefund(uint256 routerplusPayloadId_) external; + function requestRefund(uint256 routerplusPayloadId_, uint256 requestedAmount) external; /// @dev only callable by core state registry rescuer /// @notice approves a refund for the rebalance and sends funds to the receiver diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 4a37e1d0a..399f7a5f9 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -268,7 +268,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou < ((data.expectedAmountInterimAsset * (ENTIRE_SLIPPAGE - data.slippage))) ) { - refunds[args_.routerPlusPayloadId] = Refund(args_.receiverAddressSP, data.interimAsset); + refunds[args_.routerPlusPayloadId] = Refund(args_.receiverAddressSP, data.interimAsset, 0); emit RefundInitiated( args_.routerPlusPayloadId, args_.receiverAddressSP, data.interimAsset, args_.amountReceivedInterimAsset @@ -441,11 +441,9 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou revert REQUESTED_AMOUNT_TOO_HIGH(); } - uint256 amountToRefund = requestedAmount; + r.amount = requestedAmount; - r.amount = amountToRefund; - - emit refundRequested(routerPlusPayloadId_, msg.sender, r.interimToken, r.amount); + emit refundRequested(routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount); } /// @inheritdoc ISuperformRouterPlusAsync @@ -454,8 +452,6 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou Refund memory r = refunds[routerPlusPayloadId_]; - if (r.amount == 0) revert INVALID_REFUND_DATA(); - approvedRefund[routerPlusPayloadId_] = true; /// @dev deleting to prevent re-entrancy diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index b7ec0ccaa..c83cd6dcd 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1703,12 +1703,12 @@ contract SuperformRouterPlusTest is ProtocolActions { /// @dev testing invalid requester vm.startPrank(address(222)); vm.expectRevert(ISuperformRouterPlusAsync.INVALID_REQUESTER.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); vm.stopPrank(); /// @dev testing valid refund request - //SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1000); - //vm.stopPrank(); + vm.prank(deployer); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); // Step 6: Approve refund From 3684d11efa41a0d1bb68815965001d10b0105e23 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:23:14 +0200 Subject: [PATCH 41/51] test requested refund amount > expected --- test/unit/router-plus/SuperformRouterPlus.t.sol | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index c83cd6dcd..882908183 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1710,6 +1710,12 @@ contract SuperformRouterPlusTest is ProtocolActions { vm.prank(deployer); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); + // @dev testing refund amount exceeds expected amount + vm.startPrank(deployer); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 10_000e18); + vm.expectRevert(ISuperformRouterPlusAsync.REQUESTED_AMOUNT_TOO_HIGH.selector); + vm.stopPrank(); + // Step 6: Approve refund /// @dev testing invalid approver @@ -1718,13 +1724,6 @@ contract SuperformRouterPlusTest is ProtocolActions { SuperformRouterPlusAsync(address(1234)).approveRefund(1); vm.stopPrank(); - /// @dev testing refund amount exceeds expected amount - // vm.startPrank(deployer); - // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1); - // vm.expectRevert(ISuperformRouterPlusAsync.REFUND_AMOUNT_EXCEEDS_EXPECTED_AMOUNT.selector); - // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); - // vm.stopPrank(); - (, address refundToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); From 1d1e450d73113c8446f84bee3e3555b9941c5f47 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:27:20 +0200 Subject: [PATCH 42/51] fix: update requested amount too high test --- test/unit/router-plus/SuperformRouterPlus.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 882908183..dc2c1567c 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1712,8 +1712,8 @@ contract SuperformRouterPlusTest is ProtocolActions { // @dev testing refund amount exceeds expected amount vm.startPrank(deployer); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 10_000e18); vm.expectRevert(ISuperformRouterPlusAsync.REQUESTED_AMOUNT_TOO_HIGH.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 10_000e18); vm.stopPrank(); // Step 6: Approve refund From c6191c57260ccb0b2b8cd86de705888dea12ce78 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:26:43 +0200 Subject: [PATCH 43/51] chore: update refund tests --- test/unit/router-plus/SuperformRouterPlus.t.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index dc2c1567c..2f7814950 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1700,7 +1700,7 @@ contract SuperformRouterPlusTest is ProtocolActions { // Step 5: Request refund - /// @dev testing invalid requester + /// @dev testing invalid requester (not receiver) vm.startPrank(address(222)); vm.expectRevert(ISuperformRouterPlusAsync.INVALID_REQUESTER.selector); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); @@ -1709,6 +1709,7 @@ contract SuperformRouterPlusTest is ProtocolActions { /// @dev testing valid refund request vm.prank(deployer); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); + assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).requestedAmount, 100); // @dev testing refund amount exceeds expected amount vm.startPrank(deployer); @@ -1718,7 +1719,7 @@ contract SuperformRouterPlusTest is ProtocolActions { // Step 6: Approve refund - /// @dev testing invalid approver + /// @dev testing invalid approver (not core state registry) vm.startPrank(address(1234)); vm.expectRevert(); SuperformRouterPlusAsync(address(1234)).approveRefund(1); @@ -1735,9 +1736,16 @@ contract SuperformRouterPlusTest is ProtocolActions { uint256 balanceAfter = MockERC20(refundToken).balanceOf(deployer); assertGt(balanceAfter, balanceBefore); + assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).interimToken, address(0)); + + assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).receiver, address(0)); + + assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).requestedAmount, 0); + /// @dev testing refund already approved vm.expectRevert(ISuperformRouterPlusAsync.REFUND_ALREADY_APPROVED.selector); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); + vm.stopPrank(); } function test_crossChainRebalance_negativeSlippage() public { From ff9a43a77d80524dc39cfc0db782b3bd0d06abc5 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:01:01 +0200 Subject: [PATCH 44/51] fix: update amount setter in requestRefund() --- src/router-plus/SuperformRouterPlusAsync.sol | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/router-plus/SuperformRouterPlusAsync.sol b/src/router-plus/SuperformRouterPlusAsync.sol index 399f7a5f9..5caa5fcde 100644 --- a/src/router-plus/SuperformRouterPlusAsync.sol +++ b/src/router-plus/SuperformRouterPlusAsync.sol @@ -249,10 +249,6 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou revert Error.INSUFFICIENT_BALANCE(); } - if (data.expectedAmountInterimAsset == 0) { - revert Error.ZERO_AMOUNT(); - } - /// @dev We don't allow negative slippage (and funds are not rescued) /// @notice This means that a keeper has to re-submit a completeCrossChainRebalance call /// @notice With an amount received lower than expected @@ -441,7 +437,7 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou revert REQUESTED_AMOUNT_TOO_HIGH(); } - r.amount = requestedAmount; + refunds[routerPlusPayloadId_] = Refund(msg.sender, data.interimAsset, requestedAmount); emit refundRequested(routerPlusPayloadId_, msg.sender, r.interimToken, requestedAmount); } From 74645119bb8d9a1dd1d720bf8d8a8ef0f03e4f0f Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:01:15 +0200 Subject: [PATCH 45/51] chore: add extra tests for requestRefund() --- .../router-plus/SuperformRouterPlus.t.sol | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 2f7814950..64e5f35b1 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1706,17 +1706,22 @@ contract SuperformRouterPlusTest is ProtocolActions { SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); vm.stopPrank(); - /// @dev testing valid refund request - vm.prank(deployer); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); - assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).requestedAmount, 100); - // @dev testing refund amount exceeds expected amount vm.startPrank(deployer); vm.expectRevert(ISuperformRouterPlusAsync.REQUESTED_AMOUNT_TOO_HIGH.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 10_000e18); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 1000e18); vm.stopPrank(); + /// @dev testing valid refund request + vm.prank(deployer); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100); + + (,, uint256 requestedAmount) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + assertEq(requestedAmount, 100); + + (, address refundToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + assertEq(refundToken, address(args.interimAsset)); + // Step 6: Approve refund /// @dev testing invalid approver (not core state registry) @@ -1725,22 +1730,26 @@ contract SuperformRouterPlusTest is ProtocolActions { SuperformRouterPlusAsync(address(1234)).approveRefund(1); vm.stopPrank(); - (, address refundToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + /// @dev testing valid refund approval uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); - /// @dev testing valid refund approval vm.startPrank(deployer); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); vm.stopPrank(); uint256 balanceAfter = MockERC20(refundToken).balanceOf(deployer); assertGt(balanceAfter, balanceBefore); + assertEq(MockERC20(refundToken).balanceOf(address(ROUTER_PLUS_ASYNC_SOURCE)), 0); + assertEq(MockERC20(refundToken).balanceOf(address(deployer)), balanceBefore + 100); - assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).interimToken, address(0)); + (, address interimToken, ) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + assertEq(interimToken, address(0)); - assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).receiver, address(0)); + (, address receiver, ) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + assertEq(receiver, address(0)); - assertEq(SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1).requestedAmount, 0); + (,, uint256 updatedRequestedAmount) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + assertEq(updatedRequestedAmount, 0); /// @dev testing refund already approved vm.expectRevert(ISuperformRouterPlusAsync.REFUND_ALREADY_APPROVED.selector); @@ -1937,6 +1946,45 @@ contract SuperformRouterPlusTest is ProtocolActions { completeArgs.routerPlusPayloadId = 2; vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_INVALID_TX_DATA_UPDATE.selector); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); + vm.stopPrank(); + + // Test COMPLETE_REBALANCE_DIFFERENT_RECEIVER error + // SingleVaultSFData memory sfDataInvalidReceiver = SingleVaultSFData({ + // superformId: superformId1, + // amount: 1e18, + // outputAmount: 1e18, + // maxSlippage: 100, + // liqRequest: LiqRequest({ + // txData: "", + // token: getContract(SOURCE_CHAIN, "DAI"), + // interimToken: address(0), + // bridgeId: 1, + // liqDstChainId: SOURCE_CHAIN, + // nativeAmount: 0 + // }), + // permit2data: "", + // hasDstSwap: false, + // retain4626: false, + // receiverAddress: address(deployer), + // receiverAddressSP: address(12345), + // extraFormData: "" + // }); + + // data = IBaseSuperformRouterPlus.XChainRebalanceData({ + // rebalanceSelector: IBaseRouter.singleDirectSingleVaultDeposit.selector, + // interimAsset: getContract(SOURCE_CHAIN, "DAI"), + // slippage: 100, + // expectedAmountInterimAsset: 1e18, + // rebalanceToAmbIds: new uint8[][](0), + // rebalanceToDstChainIds: new uint64[](0), + // rebalanceToSfData: abi.encode(sfDataInvalidReceiver) + // }); + + // vm.startPrank(deployer); + // completeArgs.routerPlusPayloadId = 2; + // vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); + // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); + // vm.stopPrank(); } ////////////////////////////////////////////////////////////// From 2375ce7c0878aaf42daa377b11d7a61489b389ad Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:07:57 +0200 Subject: [PATCH 46/51] fix: update invalid approver error selector --- .../router-plus/SuperformRouterPlus.t.sol | 50 +++---------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 64e5f35b1..04dde5a44 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1726,20 +1726,20 @@ contract SuperformRouterPlusTest is ProtocolActions { /// @dev testing invalid approver (not core state registry) vm.startPrank(address(1234)); - vm.expectRevert(); - SuperformRouterPlusAsync(address(1234)).approveRefund(1); + vm.expectRevert(ISuperformRouterPlusAsync.NOT_CORE_STATE_REGISTRY_RESCUER.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); vm.stopPrank(); /// @dev testing valid refund approval uint256 balanceBefore = MockERC20(refundToken).balanceOf(deployer); - + uint256 routerBalanceBefore = MockERC20(refundToken).balanceOf(address(ROUTER_PLUS_ASYNC_SOURCE)); vm.startPrank(deployer); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); vm.stopPrank(); uint256 balanceAfter = MockERC20(refundToken).balanceOf(deployer); assertGt(balanceAfter, balanceBefore); - assertEq(MockERC20(refundToken).balanceOf(address(ROUTER_PLUS_ASYNC_SOURCE)), 0); + assertEq(MockERC20(refundToken).balanceOf(address(ROUTER_PLUS_ASYNC_SOURCE)), routerBalanceBefore - 100); assertEq(MockERC20(refundToken).balanceOf(address(deployer)), balanceBefore + 100); (, address interimToken, ) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); @@ -1750,8 +1750,10 @@ contract SuperformRouterPlusTest is ProtocolActions { (,, uint256 updatedRequestedAmount) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); assertEq(updatedRequestedAmount, 0); + vm.stopPrank(); /// @dev testing refund already approved + vm.startPrank(deployer); vm.expectRevert(ISuperformRouterPlusAsync.REFUND_ALREADY_APPROVED.selector); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).approveRefund(1); vm.stopPrank(); @@ -1811,6 +1813,8 @@ contract SuperformRouterPlusTest is ProtocolActions { function test_crossChainRebalance_updateSuperformData_allErrors() public { vm.selectFork(FORKS[SOURCE_CHAIN]); + uint64 REBALANCE_TO = OP; + SingleVaultSFData memory sfData = SingleVaultSFData({ superformId: superformId1, amount: 1e18, @@ -1947,44 +1951,6 @@ contract SuperformRouterPlusTest is ProtocolActions { vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_INVALID_TX_DATA_UPDATE.selector); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); vm.stopPrank(); - - // Test COMPLETE_REBALANCE_DIFFERENT_RECEIVER error - // SingleVaultSFData memory sfDataInvalidReceiver = SingleVaultSFData({ - // superformId: superformId1, - // amount: 1e18, - // outputAmount: 1e18, - // maxSlippage: 100, - // liqRequest: LiqRequest({ - // txData: "", - // token: getContract(SOURCE_CHAIN, "DAI"), - // interimToken: address(0), - // bridgeId: 1, - // liqDstChainId: SOURCE_CHAIN, - // nativeAmount: 0 - // }), - // permit2data: "", - // hasDstSwap: false, - // retain4626: false, - // receiverAddress: address(deployer), - // receiverAddressSP: address(12345), - // extraFormData: "" - // }); - - // data = IBaseSuperformRouterPlus.XChainRebalanceData({ - // rebalanceSelector: IBaseRouter.singleDirectSingleVaultDeposit.selector, - // interimAsset: getContract(SOURCE_CHAIN, "DAI"), - // slippage: 100, - // expectedAmountInterimAsset: 1e18, - // rebalanceToAmbIds: new uint8[][](0), - // rebalanceToDstChainIds: new uint64[](0), - // rebalanceToSfData: abi.encode(sfDataInvalidReceiver) - // }); - - // vm.startPrank(deployer); - // completeArgs.routerPlusPayloadId = 2; - // vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); - // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); - // vm.stopPrank(); } ////////////////////////////////////////////////////////////// From 7d732563f4c6558c6d514c24bd0e73ce7db10151 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:10:34 +0200 Subject: [PATCH 47/51] chore: rm unused variable --- Makefile | 2 +- test/unit/router-plus/SuperformRouterPlus.t.sol | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dfc8845e4..349f59aff 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ build-sizes: ## Builds the project and shows sizes .PHONY: test-vvv test-vvv: ## Runs tests with verbose output - forge test --match-contract SDMVW0TokenInputNoSlippageAMB1323 --evm-version cancun -vvv + forge test --match-contract SuperformRouterPlusTest --evm-version cancun -vvv .PHONY: ftest ftest: ## Runs tests with cancun evm version diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 04dde5a44..dc7d4b816 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1813,7 +1813,6 @@ contract SuperformRouterPlusTest is ProtocolActions { function test_crossChainRebalance_updateSuperformData_allErrors() public { vm.selectFork(FORKS[SOURCE_CHAIN]); - uint64 REBALANCE_TO = OP; SingleVaultSFData memory sfData = SingleVaultSFData({ superformId: superformId1, From 70d80216455354a6ed8b226d5d12534efbb11b83 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:10:59 +0200 Subject: [PATCH 48/51] fix: update test-vvv --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 349f59aff..dfc8845e4 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ build-sizes: ## Builds the project and shows sizes .PHONY: test-vvv test-vvv: ## Runs tests with verbose output - forge test --match-contract SuperformRouterPlusTest --evm-version cancun -vvv + forge test --match-contract SDMVW0TokenInputNoSlippageAMB1323 --evm-version cancun -vvv .PHONY: ftest ftest: ## Runs tests with cancun evm version From 60dc92d0bf3546f9cd437196fb980ed42f7981a2 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Thu, 24 Oct 2024 20:50:40 +0200 Subject: [PATCH 49/51] fix: update test_crossChainRebalance_updateSuperformData_DifferentReceiverError() --- .../router-plus/SuperformRouterPlus.t.sol | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index dc7d4b816..fa9248fd2 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1952,6 +1952,64 @@ contract SuperformRouterPlusTest is ProtocolActions { vm.stopPrank(); } + + function test_crossChainRebalance_updateSuperformData_DifferentReceiverError() public { + vm.startPrank(deployer); + + vm.makePersistent(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); + vm.makePersistent(getContract(SOURCE_CHAIN, "DAI")); + + SingleVaultSFData memory sfData = SingleVaultSFData({ + superformId: superformId1, + amount: 1e18, + outputAmount: 1e18, + maxSlippage: 100, + liqRequest: LiqRequest({ + txData: "", + token: getContract(SOURCE_CHAIN, "DAI"), + interimToken: getContract(SOURCE_CHAIN, "DAI"), + bridgeId: 1, + liqDstChainId: SOURCE_CHAIN, + nativeAmount: 0 + }), + permit2data: "", + hasDstSwap: false, + retain4626: false, + receiverAddress: address(deployer), + receiverAddressSP: address(deployer), + extraFormData: "" + }); + + uint256[][] memory newAmounts = new uint256[][](1); + newAmounts[0] = new uint256[](1); + newAmounts[0][0] = 1e18; + + uint256[][] memory newOutputAmounts = new uint256[][](1); + newOutputAmounts[0] = new uint256[](1); + newOutputAmounts[0][0] = 1e18; + + LiqRequest[][] memory liqRequests = new LiqRequest[][](1); + liqRequests[0] = new LiqRequest[](1); + liqRequests[0][0] = sfData.liqRequest; + + deal(sfData.liqRequest.token, address(ROUTER_PLUS_ASYNC_SOURCE), 1e18); + + ISuperformRouterPlusAsync.CompleteCrossChainRebalanceArgs memory completeArgs = ISuperformRouterPlusAsync + .CompleteCrossChainRebalanceArgs({ + receiverAddressSP: address(12345), + routerPlusPayloadId: 1, + amountReceivedInterimAsset: 1e18, + newAmounts: newAmounts, + newOutputAmounts: newOutputAmounts, + liqRequests: liqRequests + }); + + vm.startPrank(deployer); + vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); + vm.stopPrank(); + } + ////////////////////////////////////////////////////////////// // SAME_CHAIN REBALANCING TESTS // ////////////////////////////////////////////////////////////// From bde75d9b0bb77d19d77c9e94ba2329497ba06a08 Mon Sep 17 00:00:00 2001 From: Tamara Ringas <69479754+TamaraRingas@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:39:32 +0200 Subject: [PATCH 50/51] wip: update test_crossChainRebalance_updateSuperformData_DifferentReceiverError() --- .../router-plus/SuperformRouterPlus.t.sol | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index fa9248fd2..00ffc8f3a 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -2004,7 +2004,181 @@ contract SuperformRouterPlusTest is ProtocolActions { liqRequests: liqRequests }); + // vm.startPrank(deployer); + + // uint64 REBALANCE_FROM = ETH; + // uint64 REBALANCE_TO = OP; + + // // Step 1: Initial XCHAIN Deposit + // _xChainDeposit(superformId5ETH, REBALANCE_FROM, 1); + + // // Step 2: Start cross-chain rebalance + // vm.makePersistent(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); + // vm.makePersistent(getContract(SOURCE_CHAIN, "DAI")); + // vm.selectFork(FORKS[SOURCE_CHAIN]); + // // ISuperformRouterPlus.InitiateXChainRebalanceArgs memory args = + // // _buildInitiateXChainRebalanceArgs(REBALANCE_FROM, REBALANCE_TO, deployer); + + // ISuperformRouterPlus.InitiateXChainRebalanceArgs memory args; + // args.id = superformId5ETH; + // args.sharesToRedeem = SuperPositions(SUPER_POSITIONS_SOURCE).balanceOf(deployer, superformId5ETH); + // args.interimAsset = getContract(SOURCE_CHAIN, "DAI"); + // args.receiverAddressSP = address(deployer); + // vm.selectFork(FORKS[REBALANCE_FROM]); + // uint256 expectedAmountOfRebalanceFrom = IBaseForm(superform5ETH).previewRedeemFrom(args.sharesToRedeem); + // // conversion from DAI on DSTCHAIN to DAI on SOURCE CHAIN + // args.expectedAmountInterimAsset = _convertDecimals( + // expectedAmountOfRebalanceFrom, + // getContract(REBALANCE_FROM, "DAI"), + // args.interimAsset, + // REBALANCE_FROM, + // SOURCE_CHAIN + // ); + // //vm.selectFork(initialFork); + // args.finalizeSlippage = 100; // 1% + // //args.callData = _callDataRebalanceFromXChain(args.interimAsset, superformId5ETH, REBALANCE_FROM); + + // LiqBridgeTxDataArgs memory liqBridgeTxDataArgs = LiqBridgeTxDataArgs( + // 1, + // getContract(REBALANCE_TO, "DAI"), + // getContract(REBALANCE_TO, "DAI"), + // getContract(REBALANCE_TO, "DAI"), + // getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync"), + // REBALANCE_TO, + // REBALANCE_TO, + // REBALANCE_TO, + // false, + // getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync"), + // uint256(REBALANCE_TO), + // 1e18, + // //1e18, + // true, + // /// @dev placeholder value, not used + // 0, + // 1, + // 1, + // 1, + // address(0) + // ); + + // SingleVaultSFData memory data = SingleVaultSFData( + // superformId5ETH, + // 1e18, + // 1e18, + // 100, + // LiqRequest(_buildLiqBridgeTxData(liqBridgeTxDataArgs, false), getContract(REBALANCE_FROM, "DAI"), address(0), 1, SOURCE_CHAIN, 0), + // "", + // false, + // false, + // ROUTER_PLUS_ASYNC_SOURCE, + // deployer, + // "" + // ); + + // args.callData = abi.encodeCall( + // IBaseRouter.singleXChainSingleVaultWithdraw, SingleXChainSingleVaultStateReq(AMBs, REBALANCE_FROM, data) + // ); + + // /// @dev rebalance to call data formulation for a xchain deposit + // args.rebalanceToSelector = IBaseRouter.singleXChainSingleVaultDeposit.selector; + + // args.rebalanceToAmbIds = new uint8[][](1); + // args.rebalanceToAmbIds[0] = AMBs; + // args.rebalanceToDstChainIds = new uint64[](1); + // args.rebalanceToDstChainIds[0] = REBALANCE_TO; + + // vm.selectFork(FORKS[REBALANCE_TO]); + + // (address superformRebalanceTo,,) = superformId4OP.getSuperform(); + // address underlyingTokenRebalanceTo = IBaseForm(superformRebalanceTo).getVaultAsset(); + // /// data for a bridge from Router to Core State Registry + // // LiqBridgeTxDataArgs memory liqBridgeTxDataArgs = LiqBridgeTxDataArgs( + // // 1, + // // args.interimAsset, + // // getContract(SOURCE_CHAIN, ERC20(underlyingTokenRebalanceTo).symbol()), + // // underlyingTokenRebalanceTo, + // // getContract(SOURCE_CHAIN, "SuperformRouter"), + // // SOURCE_CHAIN, + // // REBALANCE_TO, + // // REBALANCE_TO, + // // false, + // // getContract(REBALANCE_TO, "CoreStateRegistry"), + // // uint256(REBALANCE_TO), + // // 1e18, + // // //1e18, + // // false, + // // /// @dev placeholder value, not used + // // 0, + // // 1, + // // 1, + // // 1, + // // address(0) + // // ); + + // // conversion from USDC on SOURCE CHAIN to DAI on DSTCHAIN + // uint256 expectedAmountToReceiveAfterBridge = _convertDecimals( + // args.expectedAmountInterimAsset, + // args.interimAsset, + // getContract(REBALANCE_TO, "DAI"), + // SOURCE_CHAIN, + // REBALANCE_TO + // ); + + // uint256 expectedOutputAmount = IBaseForm(superform4OP).previewDepositTo(expectedAmountToReceiveAfterBridge); + + // SingleVaultSFData memory sfData = SingleVaultSFData({ + // superformId: superformId4OP, + // amount: expectedAmountToReceiveAfterBridge, + // outputAmount: expectedOutputAmount, + // maxSlippage: 100, + // liqRequest: LiqRequest({ + // txData: _buildLiqBridgeTxData(liqBridgeTxDataArgs, false), + // token: args.interimAsset, + // interimToken: address(0), + // bridgeId: 1, + // liqDstChainId: REBALANCE_TO, + // nativeAmount: 0 + // }), + // permit2data: "", + // hasDstSwap: false, + // retain4626: false, + // receiverAddress: address(deployer), + // receiverAddressSP: address(deployer), + // extraFormData: "" + // }); + // args.rebalanceToSfData = abi.encode(sfData); + + // vm.selectFork(REBALANCE_FROM); + + // vm.startPrank(deployer); + + // SuperPositions(SUPER_POSITIONS_SOURCE).increaseAllowance( + // ROUTER_PLUS_SOURCE, superformId5ETH, args.sharesToRedeem + // ); + // vm.recordLogs(); + // SuperformRouterPlus(ROUTER_PLUS_SOURCE).startCrossChainRebalance{ value: 2 ether }(args); + + // // Step 3: Process XChain Withdraw (rebalance from) + // uint256 balanceOfInterimAssetBefore = + // MockERC20(args.interimAsset).balanceOf(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); + + // _processXChainWithdrawOneVault(SOURCE_CHAIN, REBALANCE_FROM, vm.getRecordedLogs(), 2); + + // vm.selectFork(FORKS[SOURCE_CHAIN]); + // uint256 balanceOfInterimAssetAfter = + // MockERC20(args.interimAsset).balanceOf(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); + + // uint256 interimAmountOnRouterPlusAsync = balanceOfInterimAssetAfter - balanceOfInterimAssetBefore; + + // ISuperformRouterPlusAsync.CompleteCrossChainRebalanceArgs memory completeArgs = + // _buildCompleteCrossChainRebalanceArgs(interimAmountOnRouterPlusAsync, superformId4OP, REBALANCE_TO); + + // Step 4: Complete cross-chain rebalance vm.startPrank(deployer); + //completeArgs.amountReceivedInterimAsset = completeArgs.amountReceivedInterimAsset / 3; + //completeArgs.liqRequests[0][0].token = getContract(SOURCE_CHAIN, "DAI"); + //completeArgs.liqRequests[0][0].interimToken = getContract(SOURCE_CHAIN, "DAI"); + completeArgs.receiverAddressSP = address(12345); vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); vm.stopPrank(); From 48e30157a66920db68a10fa466d7913b7f3bdb8a Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:05:10 +0100 Subject: [PATCH 51/51] test: fix --- Makefile | 2 +- .../router-plus/SuperformRouterPlus.t.sol | 253 +----------------- 2 files changed, 14 insertions(+), 241 deletions(-) diff --git a/Makefile b/Makefile index dfc8845e4..3bc53220d 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ build-sizes: ## Builds the project and shows sizes .PHONY: test-vvv test-vvv: ## Runs tests with verbose output - forge test --match-contract SDMVW0TokenInputNoSlippageAMB1323 --evm-version cancun -vvv + forge test --match-test test_crossChainRebalance_updateSuperformData_allErrors --evm-version cancun -vvv .PHONY: ftest ftest: ## Runs tests with cancun evm version diff --git a/test/unit/router-plus/SuperformRouterPlus.t.sol b/test/unit/router-plus/SuperformRouterPlus.t.sol index 00ffc8f3a..8694aeed3 100644 --- a/test/unit/router-plus/SuperformRouterPlus.t.sol +++ b/test/unit/router-plus/SuperformRouterPlus.t.sol @@ -1742,10 +1742,10 @@ contract SuperformRouterPlusTest is ProtocolActions { assertEq(MockERC20(refundToken).balanceOf(address(ROUTER_PLUS_ASYNC_SOURCE)), routerBalanceBefore - 100); assertEq(MockERC20(refundToken).balanceOf(address(deployer)), balanceBefore + 100); - (, address interimToken, ) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + (, address interimToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); assertEq(interimToken, address(0)); - (, address receiver, ) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); + (, address receiver,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); assertEq(receiver, address(0)); (,, uint256 updatedRequestedAmount) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1); @@ -1921,14 +1921,19 @@ contract SuperformRouterPlusTest is ProtocolActions { // Reset liqDstChainId completeArgs.liqRequests[0][0].liqDstChainId = SOURCE_CHAIN; - - /// @FIXME: This line is not reacheable - // vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); - // completeArgs.receiverAddressSP = address(0x123); - // SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether - // }(completeArgs); vm.stopPrank(); + vm.startPrank(ROUTER_PLUS_SOURCE); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).setXChainRebalanceCallData(address(0x123), 2, data); + vm.stopPrank(); + vm.startPrank(deployer); + vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); + completeArgs.routerPlusPayloadId = 2; + completeArgs.receiverAddressSP = address(0x123); + SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); + vm.stopPrank(); + completeArgs.routerPlusPayloadId = 1; + completeArgs.receiverAddressSP = deployer; sfData.liqRequest.token = address(0); data = IBaseSuperformRouterPlus.XChainRebalanceData({ @@ -1952,238 +1957,6 @@ contract SuperformRouterPlusTest is ProtocolActions { vm.stopPrank(); } - - function test_crossChainRebalance_updateSuperformData_DifferentReceiverError() public { - vm.startPrank(deployer); - - vm.makePersistent(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); - vm.makePersistent(getContract(SOURCE_CHAIN, "DAI")); - - SingleVaultSFData memory sfData = SingleVaultSFData({ - superformId: superformId1, - amount: 1e18, - outputAmount: 1e18, - maxSlippage: 100, - liqRequest: LiqRequest({ - txData: "", - token: getContract(SOURCE_CHAIN, "DAI"), - interimToken: getContract(SOURCE_CHAIN, "DAI"), - bridgeId: 1, - liqDstChainId: SOURCE_CHAIN, - nativeAmount: 0 - }), - permit2data: "", - hasDstSwap: false, - retain4626: false, - receiverAddress: address(deployer), - receiverAddressSP: address(deployer), - extraFormData: "" - }); - - uint256[][] memory newAmounts = new uint256[][](1); - newAmounts[0] = new uint256[](1); - newAmounts[0][0] = 1e18; - - uint256[][] memory newOutputAmounts = new uint256[][](1); - newOutputAmounts[0] = new uint256[](1); - newOutputAmounts[0][0] = 1e18; - - LiqRequest[][] memory liqRequests = new LiqRequest[][](1); - liqRequests[0] = new LiqRequest[](1); - liqRequests[0][0] = sfData.liqRequest; - - deal(sfData.liqRequest.token, address(ROUTER_PLUS_ASYNC_SOURCE), 1e18); - - ISuperformRouterPlusAsync.CompleteCrossChainRebalanceArgs memory completeArgs = ISuperformRouterPlusAsync - .CompleteCrossChainRebalanceArgs({ - receiverAddressSP: address(12345), - routerPlusPayloadId: 1, - amountReceivedInterimAsset: 1e18, - newAmounts: newAmounts, - newOutputAmounts: newOutputAmounts, - liqRequests: liqRequests - }); - - // vm.startPrank(deployer); - - // uint64 REBALANCE_FROM = ETH; - // uint64 REBALANCE_TO = OP; - - // // Step 1: Initial XCHAIN Deposit - // _xChainDeposit(superformId5ETH, REBALANCE_FROM, 1); - - // // Step 2: Start cross-chain rebalance - // vm.makePersistent(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); - // vm.makePersistent(getContract(SOURCE_CHAIN, "DAI")); - // vm.selectFork(FORKS[SOURCE_CHAIN]); - // // ISuperformRouterPlus.InitiateXChainRebalanceArgs memory args = - // // _buildInitiateXChainRebalanceArgs(REBALANCE_FROM, REBALANCE_TO, deployer); - - // ISuperformRouterPlus.InitiateXChainRebalanceArgs memory args; - // args.id = superformId5ETH; - // args.sharesToRedeem = SuperPositions(SUPER_POSITIONS_SOURCE).balanceOf(deployer, superformId5ETH); - // args.interimAsset = getContract(SOURCE_CHAIN, "DAI"); - // args.receiverAddressSP = address(deployer); - // vm.selectFork(FORKS[REBALANCE_FROM]); - // uint256 expectedAmountOfRebalanceFrom = IBaseForm(superform5ETH).previewRedeemFrom(args.sharesToRedeem); - // // conversion from DAI on DSTCHAIN to DAI on SOURCE CHAIN - // args.expectedAmountInterimAsset = _convertDecimals( - // expectedAmountOfRebalanceFrom, - // getContract(REBALANCE_FROM, "DAI"), - // args.interimAsset, - // REBALANCE_FROM, - // SOURCE_CHAIN - // ); - // //vm.selectFork(initialFork); - // args.finalizeSlippage = 100; // 1% - // //args.callData = _callDataRebalanceFromXChain(args.interimAsset, superformId5ETH, REBALANCE_FROM); - - // LiqBridgeTxDataArgs memory liqBridgeTxDataArgs = LiqBridgeTxDataArgs( - // 1, - // getContract(REBALANCE_TO, "DAI"), - // getContract(REBALANCE_TO, "DAI"), - // getContract(REBALANCE_TO, "DAI"), - // getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync"), - // REBALANCE_TO, - // REBALANCE_TO, - // REBALANCE_TO, - // false, - // getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync"), - // uint256(REBALANCE_TO), - // 1e18, - // //1e18, - // true, - // /// @dev placeholder value, not used - // 0, - // 1, - // 1, - // 1, - // address(0) - // ); - - // SingleVaultSFData memory data = SingleVaultSFData( - // superformId5ETH, - // 1e18, - // 1e18, - // 100, - // LiqRequest(_buildLiqBridgeTxData(liqBridgeTxDataArgs, false), getContract(REBALANCE_FROM, "DAI"), address(0), 1, SOURCE_CHAIN, 0), - // "", - // false, - // false, - // ROUTER_PLUS_ASYNC_SOURCE, - // deployer, - // "" - // ); - - // args.callData = abi.encodeCall( - // IBaseRouter.singleXChainSingleVaultWithdraw, SingleXChainSingleVaultStateReq(AMBs, REBALANCE_FROM, data) - // ); - - // /// @dev rebalance to call data formulation for a xchain deposit - // args.rebalanceToSelector = IBaseRouter.singleXChainSingleVaultDeposit.selector; - - // args.rebalanceToAmbIds = new uint8[][](1); - // args.rebalanceToAmbIds[0] = AMBs; - // args.rebalanceToDstChainIds = new uint64[](1); - // args.rebalanceToDstChainIds[0] = REBALANCE_TO; - - // vm.selectFork(FORKS[REBALANCE_TO]); - - // (address superformRebalanceTo,,) = superformId4OP.getSuperform(); - // address underlyingTokenRebalanceTo = IBaseForm(superformRebalanceTo).getVaultAsset(); - // /// data for a bridge from Router to Core State Registry - // // LiqBridgeTxDataArgs memory liqBridgeTxDataArgs = LiqBridgeTxDataArgs( - // // 1, - // // args.interimAsset, - // // getContract(SOURCE_CHAIN, ERC20(underlyingTokenRebalanceTo).symbol()), - // // underlyingTokenRebalanceTo, - // // getContract(SOURCE_CHAIN, "SuperformRouter"), - // // SOURCE_CHAIN, - // // REBALANCE_TO, - // // REBALANCE_TO, - // // false, - // // getContract(REBALANCE_TO, "CoreStateRegistry"), - // // uint256(REBALANCE_TO), - // // 1e18, - // // //1e18, - // // false, - // // /// @dev placeholder value, not used - // // 0, - // // 1, - // // 1, - // // 1, - // // address(0) - // // ); - - // // conversion from USDC on SOURCE CHAIN to DAI on DSTCHAIN - // uint256 expectedAmountToReceiveAfterBridge = _convertDecimals( - // args.expectedAmountInterimAsset, - // args.interimAsset, - // getContract(REBALANCE_TO, "DAI"), - // SOURCE_CHAIN, - // REBALANCE_TO - // ); - - // uint256 expectedOutputAmount = IBaseForm(superform4OP).previewDepositTo(expectedAmountToReceiveAfterBridge); - - // SingleVaultSFData memory sfData = SingleVaultSFData({ - // superformId: superformId4OP, - // amount: expectedAmountToReceiveAfterBridge, - // outputAmount: expectedOutputAmount, - // maxSlippage: 100, - // liqRequest: LiqRequest({ - // txData: _buildLiqBridgeTxData(liqBridgeTxDataArgs, false), - // token: args.interimAsset, - // interimToken: address(0), - // bridgeId: 1, - // liqDstChainId: REBALANCE_TO, - // nativeAmount: 0 - // }), - // permit2data: "", - // hasDstSwap: false, - // retain4626: false, - // receiverAddress: address(deployer), - // receiverAddressSP: address(deployer), - // extraFormData: "" - // }); - // args.rebalanceToSfData = abi.encode(sfData); - - // vm.selectFork(REBALANCE_FROM); - - // vm.startPrank(deployer); - - // SuperPositions(SUPER_POSITIONS_SOURCE).increaseAllowance( - // ROUTER_PLUS_SOURCE, superformId5ETH, args.sharesToRedeem - // ); - // vm.recordLogs(); - // SuperformRouterPlus(ROUTER_PLUS_SOURCE).startCrossChainRebalance{ value: 2 ether }(args); - - // // Step 3: Process XChain Withdraw (rebalance from) - // uint256 balanceOfInterimAssetBefore = - // MockERC20(args.interimAsset).balanceOf(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); - - // _processXChainWithdrawOneVault(SOURCE_CHAIN, REBALANCE_FROM, vm.getRecordedLogs(), 2); - - // vm.selectFork(FORKS[SOURCE_CHAIN]); - // uint256 balanceOfInterimAssetAfter = - // MockERC20(args.interimAsset).balanceOf(getContract(SOURCE_CHAIN, "SuperformRouterPlusAsync")); - - // uint256 interimAmountOnRouterPlusAsync = balanceOfInterimAssetAfter - balanceOfInterimAssetBefore; - - // ISuperformRouterPlusAsync.CompleteCrossChainRebalanceArgs memory completeArgs = - // _buildCompleteCrossChainRebalanceArgs(interimAmountOnRouterPlusAsync, superformId4OP, REBALANCE_TO); - - // Step 4: Complete cross-chain rebalance - vm.startPrank(deployer); - //completeArgs.amountReceivedInterimAsset = completeArgs.amountReceivedInterimAsset / 3; - //completeArgs.liqRequests[0][0].token = getContract(SOURCE_CHAIN, "DAI"); - //completeArgs.liqRequests[0][0].interimToken = getContract(SOURCE_CHAIN, "DAI"); - completeArgs.receiverAddressSP = address(12345); - vm.expectRevert(ISuperformRouterPlusAsync.COMPLETE_REBALANCE_DIFFERENT_RECEIVER.selector); - SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).completeCrossChainRebalance{ value: 1 ether }(completeArgs); - vm.stopPrank(); - } - ////////////////////////////////////////////////////////////// // SAME_CHAIN REBALANCING TESTS // //////////////////////////////////////////////////////////////