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

remove swapper callback verification #3

Merged
merged 1 commit into from
May 10, 2023
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
12 changes: 0 additions & 12 deletions src/SwapperFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ contract SwapperFactory {

SwapperImpl public immutable swapperImpl;

/// mapping of canonical swappers for flash callback validation
mapping(SwapperImpl => bool) internal $isSwapper;

constructor() {
swapperImpl = new SwapperImpl();
}
Expand All @@ -49,16 +46,7 @@ contract SwapperFactory {
oracle: oracle
});
swapper.initializer(swapperInitParams);
$isSwapper[swapper] = true;

emit CreateSwapper({swapper: swapper, params: swapperInitParams});
}

/// -----------------------------------------------------------------------
/// functions - public & external - view
/// -----------------------------------------------------------------------

function isSwapper(SwapperImpl swapper) external view returns (bool) {
return $isSwapper[swapper];
}
}
10 changes: 2 additions & 8 deletions src/integrations/UniV3Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {TokenUtils} from "splits-utils/TokenUtils.sol";

import {ISwapperFlashCallback} from "../interfaces/ISwapperFlashCallback.sol";
import {SwapperCallbackValidation} from "../peripherals/SwapperCallbackValidation.sol";
import {SwapperImpl} from "../SwapperImpl.sol";
import {SwapperFactory} from "../SwapperFactory.sol";

Expand All @@ -18,7 +17,6 @@ import {SwapperFactory} from "../SwapperFactory.sol";
/// @notice Used by EOAs & simple bots to execute swapper#flash with uniswap v3
/// This contract uses token = address(0) to refer to ETH.
contract UniV3Swap is ISwapperFlashCallback {
using SwapperCallbackValidation for SwapperFactory;
using SafeTransferLib for address;
using TokenUtils for address;

Expand Down Expand Up @@ -60,14 +58,10 @@ contract UniV3Swap is ISwapperFlashCallback {
/// swapper#flash callback
/// @dev by end of function if tokenToBeneficiary_ is eth, must have sent amountToBeneficiary_
/// to swapper#payback. Otherwise, must approve swapper to transferFrom amountToBeneficiary_
/// DO NOT HOLD FUNDS IN THIS CONTRACT WITHOUT PROPER VERIFICATION OF MSG.SENDER
function swapperFlashCallback(address tokenToBeneficiary_, uint256 amountToBeneficiary_, bytes calldata data_)
external
{
SwapperImpl swapper = SwapperImpl(msg.sender);
if (!swapperFactory.verifyCallback(swapper)) {
revert Unauthorized();
}

uint256 ethBalance = address(this).balance;
if (!tokenToBeneficiary_._isETH() && ethBalance != 0) {
weth9.deposit{value: ethBalance}();
Expand Down Expand Up @@ -99,7 +93,7 @@ contract UniV3Swap is ISwapperFlashCallback {
weth9.withdraw(weth9Balance);

// send req'd amt to swapper#payback
swapper.payback{value: amountToBeneficiary_}();
SwapperImpl(msg.sender).payback{value: amountToBeneficiary_}();

// xfr excess out
ethBalance = address(this).balance;
Expand Down
19 changes: 0 additions & 19 deletions src/peripherals/SwapperCallbackValidation.sol

This file was deleted.

11 changes: 0 additions & 11 deletions test/SwapperFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,6 @@ contract SwapperFactoryTest is BaseTest, LibCloneBase {
test_clone_canDelegateCall();
}

/// -----------------------------------------------------------------------
/// isSwapper
/// -----------------------------------------------------------------------

function test_isSwapper() public {
SwapperImpl expectedSwapper = SwapperImpl(_predictNextAddressFrom(address(swapperFactory)));
assertFalse(swapperFactory.isSwapper(expectedSwapper));
swapperFactory.createSwapper(params);
assertTrue(swapperFactory.isSwapper(expectedSwapper));
}

/// -----------------------------------------------------------------------
/// internal
/// -----------------------------------------------------------------------
Expand Down