From 5968586d440d2de7ebadaa1711c150b81304c748 Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Wed, 15 Nov 2023 14:16:48 -0500 Subject: [PATCH] Remove protocol fees --- ...derReactorIntegrationTest-testExecute.snap | 2 +- ...rIntegrationTest-testPermitAndExecute.snap | 2 +- src/base/ReactorErrors.sol | 24 +++++++++++++++ src/reactors/RelayOrderReactor.sol | 29 ++++++++----------- .../RelayOrderReactorIntegration.t.sol | 2 +- 5 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 src/base/ReactorErrors.sol diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap index acc917cc..16e7982a 100644 --- a/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testExecute.snap @@ -1 +1 @@ -264776 \ No newline at end of file +264895 \ No newline at end of file diff --git a/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap b/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap index b9c497e8..7331bbf2 100644 --- a/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap +++ b/.forge-snapshots/RelayOrderReactorIntegrationTest-testPermitAndExecute.snap @@ -1 +1 @@ -312241 \ No newline at end of file +312360 \ No newline at end of file diff --git a/src/base/ReactorErrors.sol b/src/base/ReactorErrors.sol new file mode 100644 index 00000000..508d69d6 --- /dev/null +++ b/src/base/ReactorErrors.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity ^0.8.0; + +interface ReactorErrors { + // Occurs when an output = ETH and the reactor does contain enough ETH but + // the direct filler did not include enough ETH in their call to execute/executeBatch + error InsufficientEth(); + + // A nested call failed + error CallFailed(); + + error InvalidToken(); + error UnsupportedAction(); + error ReactorCallbackNotSupported(); + + /// @notice thrown when an order's deadline is before its end time + error DeadlineBeforeEndTime(); + + /// @notice thrown when an order's end time is before its start time + error OrderEndTimeBeforeStartTime(); + + /// @notice thrown when an order's inputs and outputs both decay + error InputAndOutputDecay(); +} \ No newline at end of file diff --git a/src/reactors/RelayOrderReactor.sol b/src/reactors/RelayOrderReactor.sol index f51f33d5..50283ad6 100644 --- a/src/reactors/RelayOrderReactor.sol +++ b/src/reactors/RelayOrderReactor.sol @@ -10,6 +10,7 @@ import {IReactorCallback} from "UniswapX/src/interfaces/IReactorCallback.sol"; import {IReactor} from "UniswapX/src/interfaces/IReactor.sol"; import {ProtocolFees} from "UniswapX/src/base/ProtocolFees.sol"; import {ReactorEvents} from "../base/ReactorEvents.sol"; +import {ReactorErrors} from "../base/ReactorErrors.sol"; import {InputTokenWithRecipient, ResolvedRelayOrder} from "../base/ReactorStructs.sol"; import {CurrencyLibrary, NATIVE} from "../lib/CurrencyLibrary.sol"; import {Permit2Lib} from "../lib/Permit2Lib.sol"; @@ -19,7 +20,7 @@ import {RelayDecayLib} from "../lib/RelayDecayLib.sol"; /// @notice Reactor for relaying calls to UniversalRouter onchain /// @dev This reactor only supports V2/V3 swaps, do NOT attempt to use other Universal Router commands -contract RelayOrderReactor is ReactorEvents, ProtocolFees, ReentrancyGuard, IReactor { +contract RelayOrderReactor is ReactorEvents, ReactorErrors, ReentrancyGuard, IReactor { using SafeTransferLib for ERC20; using CurrencyLibrary for address; using Permit2Lib for ResolvedRelayOrder; @@ -27,23 +28,12 @@ contract RelayOrderReactor is ReactorEvents, ProtocolFees, ReentrancyGuard, IRea using RelayOrderLib for RelayOrder; using RelayDecayLib for InputTokenWithRecipient[]; - // Occurs when an output = ETH and the reactor does contain enough ETH but - // the direct filler did not include enough ETH in their call to execute/executeBatch - error InsufficientEth(); - // A nested call failed - error CallFailed(); - error InvalidToken(); - error UnsupportedAction(); - error ReactorCallbackNotSupported(); - /// @notice permit2 address used for token transfers and signature verification IPermit2 public immutable permit2; address public immutable universalRouter; - constructor(IPermit2 _permit2, address _protocolFeeOwner, address _universalRouter) - ProtocolFees(_protocolFeeOwner) - { + constructor(IPermit2 _permit2, address _universalRouter) { permit2 = _permit2; universalRouter = _universalRouter; } @@ -121,9 +111,6 @@ contract RelayOrderReactor is ReactorEvents, ProtocolFees, ReentrancyGuard, IRea for (uint256 i = 0; i < ordersLength; i++) { ResolvedRelayOrder memory order = orders[i]; - // TODO fees impl - // _injectFees(order); - order.validate(msg.sender); // Since relay order inputs specify recipients we don't pass in recipient here @@ -195,6 +182,14 @@ contract RelayOrderReactor is ReactorEvents, ProtocolFees, ReentrancyGuard, IRea /// @notice validate the relay order fields /// @dev Throws if the order is invalid function _validateOrder(RelayOrder memory order) internal pure { - // assert that actions are valid and allowed, that calldata is well formed, etc. + if (order.info.deadline < order.decayEndTime) { + revert DeadlineBeforeEndTime(); + } + + if (order.decayEndTime < order.decayStartTime) { + revert OrderEndTimeBeforeStartTime(); + } + + // TODO: add additional validations related to relayed actions, if desired } } diff --git a/test/integration/RelayOrderReactorIntegration.t.sol b/test/integration/RelayOrderReactorIntegration.t.sol index 3b85a8eb..7d2a5982 100644 --- a/test/integration/RelayOrderReactorIntegration.t.sol +++ b/test/integration/RelayOrderReactorIntegration.t.sol @@ -53,7 +53,7 @@ contract RelayOrderReactorIntegrationTest is GasSnapshot, Test, PermitSignature filler = makeAddr("filler"); vm.createSelectFork(vm.envString("FOUNDRY_RPC_URL"), 17972788); - deployCodeTo("RelayOrderReactor.sol", abi.encode(PERMIT2, address(0), UNIVERSAL_ROUTER), RELAY_ORDER_REACTOR); + deployCodeTo("RelayOrderReactor.sol", abi.encode(PERMIT2, UNIVERSAL_ROUTER), RELAY_ORDER_REACTOR); reactor = RelayOrderReactor(RELAY_ORDER_REACTOR); permitExecutor = new PermitExecutor(address(filler), reactor, address(filler));