Skip to content
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
2 changes: 2 additions & 0 deletions src/Swapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ contract Swapper is UUPSUpgradeable, AccessControlUpgradeable, PausableUpgradeab
} else {
IERC20(token).safeTransfer(to, amount);
}

emit TokensRecovered(token, to, amount);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/ISwapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ interface ISwapper is IAccessControl {
*/
event NativeWrapperSet(address indexed wrapper);

/**
* @notice Emitted when stranded tokens or native ETH are recovered by an admin.
* @param token Token address recovered, or the native ETH sentinel (0xEeee...eeEE).
* @param to Recipient of the recovered funds.
* @param amount Amount recovered.
*/
event TokensRecovered(address indexed token, address indexed to, uint256 amount);

/**
* @notice Reverts when a required address argument is zero.
*/
Expand Down
23 changes: 23 additions & 0 deletions test/unit/Swapper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,17 @@ contract SwapperTest is Test {
assertEq(tokenIn.balanceOf(address(swapper)), 0, "Swapper balance should be zero");
}

function test_recoverTokens_WhenValid_EmitsTokensRecovered() public {
uint256 rescueAmount = 50 ether;
tokenIn.mint(address(swapper), rescueAmount);

vm.expectEmit(true, true, false, true, address(swapper));
emit ISwapper.TokensRecovered(address(tokenIn), recipient, rescueAmount);

vm.prank(admin);
swapper.recoverTokens(address(tokenIn), recipient, rescueAmount);
}

function test_recoverTokens_WhenNativeETH_TransfersNativeETH() public {
uint256 rescueAmount = 5 ether;

Expand All @@ -433,6 +444,18 @@ contract SwapperTest is Test {
assertEq(address(swapper).balance, 0, "Swapper balance should be zero");
}

function test_recoverTokens_WhenNativeETH_EmitsTokensRecovered() public {
uint256 rescueAmount = 5 ether;
vm.deal(address(swapper), rescueAmount);
address nativeEth = swapper.NATIVE_ETH();

vm.expectEmit(true, true, false, true, address(swapper));
emit ISwapper.TokensRecovered(nativeEth, recipient, rescueAmount);

vm.prank(admin);
swapper.recoverTokens(nativeEth, recipient, rescueAmount);
}

function test_recoverTokens_WhenNativeETHTransferFails_Reverts() public {
uint256 rescueAmount = 5 ether;

Expand Down
Loading