Skip to content

fix: prevent multiple calls to request refund [sup-9336] #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/interfaces/ISuperformRouterPlusAsync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ interface ISuperformRouterPlusAsync is IBaseSuperformRouterPlus {
uint256 newOutputAmount, uint256 expectedOutputAmount, uint256 userSlippage
);

/// @notice thrown if the refund is already requested
error REFUND_ALREADY_REQUESTED();

/// @notice thrown to avoid processing the same rebalance payload twice
error REBALANCE_ALREADY_PROCESSED();

Expand Down
2 changes: 2 additions & 0 deletions src/router-plus/SuperformRouterPlusAsync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ contract SuperformRouterPlusAsync is ISuperformRouterPlusAsync, BaseSuperformRou
function requestRefund(uint256 routerPlusPayloadId_, uint256 requestedAmount) external {
Refund memory r = refunds[routerPlusPayloadId_];

if (r.amount != 0) revert REFUND_ALREADY_REQUESTED();

if (msg.sender != r.receiver) revert INVALID_REQUESTER();
if (r.interimToken == address(0)) revert INVALID_REFUND_DATA();

Expand Down
4 changes: 4 additions & 0 deletions test/unit/router-plus/SuperformRouterPlus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,10 @@ contract SuperformRouterPlusTest is ProtocolActions {
(, address refundToken,) = SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).refunds(1);
assertEq(refundToken, address(args.interimAsset));

// @dev testing refund already requested
vm.expectRevert(ISuperformRouterPlusAsync.REFUND_ALREADY_REQUESTED.selector);
SuperformRouterPlusAsync(ROUTER_PLUS_ASYNC_SOURCE).requestRefund(1, 100);

// Step 6: Approve refund

/// @dev testing invalid approver (not core state registry)
Expand Down