Skip to content
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

feat: update swapRouter02Executor #268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 1 addition & 1 deletion .forge-snapshots/SwapRouter02ExecutorExecute.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
262691
267163
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117810
118161
33 changes: 29 additions & 4 deletions src/sample-executors/SwapRouter02Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ contract SwapRouter02Executor is IReactorCallback, Owned {
using SafeTransferLib for ERC20;
using CurrencyLibrary for address;

event WhitelistedCallerChanged(address newWhitelistedCaller, address oldWhitelistedCaller);
event ReactorChanged(address newReactor, address oldReactor);

/// @notice thrown if reactorCallback is called with a non-whitelisted filler
error CallerNotWhitelisted();
/// @notice thrown if reactorCallback is called by an address other than the reactor
error MsgSenderNotReactor();

ISwapRouter02 private immutable swapRouter02;
address private immutable whitelistedCaller;
IReactor private immutable reactor;
WETH private immutable weth;
ISwapRouter02 public immutable swapRouter02;
WETH public immutable weth;

address private whitelistedCaller;
IReactor public reactor;

modifier onlyWhitelistedCaller() {
if (msg.sender != whitelistedCaller) {
Expand Down Expand Up @@ -115,6 +119,27 @@ contract SwapRouter02Executor is IReactorCallback, Owned {
SafeTransferLib.safeTransferETH(recipient, address(this).balance);
}

/// @notice Transfer the entire balance of an ERC20 token in this contract to a recipient. Can only be called by owner.
/// @param token The ERC20 token to withdraw
/// @param to The recipient of the tokens
function withdrawERC20(ERC20 token, address to) external onlyOwner {
token.safeTransfer(to, token.balanceOf(address(this)));
}

/// @notice Update the reactor contract address. Can only be called by owner.
/// @param _reactor The new reactor contract address
function updateReactor(IReactor _reactor) external onlyOwner {
emit ReactorChanged(address(_reactor), address(reactor));
reactor = _reactor;
}

/// @notice Update the whitelisted caller address. Can only be called by owner.
/// @param _whitelistedCaller The new whitelisted caller address
function updateWhitelistedCaller(address _whitelistedCaller) external onlyOwner {
emit WhitelistedCallerChanged(_whitelistedCaller, whitelistedCaller);
whitelistedCaller = _whitelistedCaller;
}

/// @notice Necessary for this contract to receive ETH when calling unwrapWETH()
receive() external payable {}
}
8 changes: 8 additions & 0 deletions test/executors/SwapRouter02Executor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ contract SwapRouter02ExecutorTest is Test, PermitSignature, GasSnapshot, DeployP
assertEq(balanceAfter - balanceBefore, 1 ether);
}

function testWithdrawERC20() public {
deal(address(weth), address(swapRouter02Executor), 1 ether);
uint256 balanceBefore = weth.balanceOf(address(this));
swapRouter02Executor.withdrawERC20(weth, address(this));
uint256 balanceAfter = weth.balanceOf(address(this));
assertEq(balanceAfter - balanceBefore, 1 ether);
}

function testWithdrawETHNotOwner() public {
vm.expectRevert("UNAUTHORIZED");
vm.prank(address(0xbeef));
Expand Down
Loading