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

Inherit from IReactor to get executeWithCallback again #15

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
254346
254413
Original file line number Diff line number Diff line change
@@ -1 +1 @@
280710
280777
Original file line number Diff line number Diff line change
@@ -1 +1 @@
310415
310482
15 changes: 0 additions & 15 deletions src/interfaces/IRelayOrderReactor.sol

This file was deleted.

12 changes: 12 additions & 0 deletions src/interfaces/IRelayOrderReactorCallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {ResolvedRelayOrder} from "../base/ReactorStructs.sol";

/// @notice Callback for executing orders through a reactor.
interface IRelayOrderReactorCallback {
/// @notice Called by the reactor after actions are exected in an order
/// @param resolvedOrders Has inputs and outputs
/// @param callbackData The callbackData specified for an order execution
function reactorCallback(ResolvedRelayOrder[] memory resolvedOrders, bytes memory callbackData) external;
}
43 changes: 41 additions & 2 deletions src/reactors/RelayOrderReactor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {IPermit2} from "permit2/src/interfaces/IPermit2.sol";
import {SignedOrder, OrderInfo} from "UniswapX/src/base/ReactorStructs.sol";
import {ReactorEvents} from "UniswapX/src/base/ReactorEvents.sol";
import {IReactor} from "UniswapX/src/interfaces/IReactor.sol";
import {CurrencyLibrary} from "UniswapX/src/lib/CurrencyLibrary.sol";
import {IRelayOrderReactor} from "../interfaces/IRelayOrderReactor.sol";
import {IRelayOrderReactorCallback} from "../interfaces/IRelayOrderReactorCallback.sol";
import {InputTokenWithRecipient, ResolvedRelayOrder} from "../base/ReactorStructs.sol";
import {ReactorErrors} from "../base/ReactorErrors.sol";
import {Permit2Lib} from "../lib/Permit2Lib.sol";
Expand All @@ -19,7 +20,7 @@ import {RelayDecayLib} from "../lib/RelayDecayLib.sol";
/// @notice Reactor for handling the execution of RelayOrders
/// @notice This contract MUST NOT have approvals or priviledged access
/// @notice any funds in this contract can be swept away by anyone
contract RelayOrderReactor is ReactorEvents, ReactorErrors, ReentrancyGuard, IRelayOrderReactor {
contract RelayOrderReactor is IReactor, ReactorEvents, ReactorErrors, ReentrancyGuard {
using SafeTransferLib for ERC20;
using CurrencyLibrary for address;
using Permit2Lib for ResolvedRelayOrder;
Expand All @@ -43,6 +44,22 @@ contract RelayOrderReactor is ReactorEvents, ReactorErrors, ReentrancyGuard, IRe
_fill(resolvedOrders);
}

/// @notice callbacks allow fillers to perform additional actions after the order is executed
/// example, to transfer in tokens to fill orders where users are owed additional amounts
function executeWithCallback(SignedOrder calldata order, bytes calldata callbackData)
external
payable
nonReentrant
{
ResolvedRelayOrder[] memory resolvedOrders = new ResolvedRelayOrder[](1);
resolvedOrders[0] = resolve(order);

_prepare(resolvedOrders);
_execute(resolvedOrders);
IRelayOrderReactorCallback(msg.sender).reactorCallback(resolvedOrders, callbackData);
_fill(resolvedOrders);
}

function executeBatch(SignedOrder[] calldata orders) external payable nonReentrant {
uint256 ordersLength = orders.length;
ResolvedRelayOrder[] memory resolvedOrders = new ResolvedRelayOrder[](ordersLength);
Expand All @@ -58,6 +75,28 @@ contract RelayOrderReactor is ReactorEvents, ReactorErrors, ReentrancyGuard, IRe
_fill(resolvedOrders);
}

/// @notice callbacks allow fillers to perform additional actions after the order is executed
/// example, to transfer in tokens to fill orders where users are owed additional amounts
function executeBatchWithCallback(SignedOrder[] calldata orders, bytes calldata callbackData)
external
payable
nonReentrant
{
uint256 ordersLength = orders.length;
ResolvedRelayOrder[] memory resolvedOrders = new ResolvedRelayOrder[](ordersLength);

unchecked {
for (uint256 i = 0; i < ordersLength; i++) {
resolvedOrders[i] = resolve(orders[i]);
}
}

_prepare(resolvedOrders);
_execute(resolvedOrders);
IRelayOrderReactorCallback(msg.sender).reactorCallback(resolvedOrders, callbackData);
_fill(resolvedOrders);
}

function _execute(ResolvedRelayOrder[] memory orders) internal {
uint256 ordersLength = orders.length;
// actions are encoded as (address target, uint256 value, bytes data)[]
Expand Down
6 changes: 3 additions & 3 deletions src/sample-executors/PermitExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Owned} from "solmate/src/auth/Owned.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {SignedOrder} from "UniswapX/src/base/ReactorStructs.sol";
import {CurrencyLibrary} from "UniswapX/src/lib/CurrencyLibrary.sol";
import {IRelayOrderReactor} from "../interfaces/IRelayOrderReactor.sol";
import {IReactor} from "UniswapX/src/interfaces/IReactor.sol";

/// @notice A simple fill contract that relays 2612 style permits on chain before filling a Relay order
contract PermitExecutor is Owned {
Expand All @@ -17,7 +17,7 @@ contract PermitExecutor is Owned {
error CallerNotWhitelisted();

address private immutable whitelistedCaller;
IRelayOrderReactor private immutable reactor;
IReactor private immutable reactor;

modifier onlyWhitelistedCaller() {
if (msg.sender != whitelistedCaller) {
Expand All @@ -26,7 +26,7 @@ contract PermitExecutor is Owned {
_;
}

constructor(address _whitelistedCaller, IRelayOrderReactor _reactor, address _owner) Owned(_owner) {
constructor(address _whitelistedCaller, IReactor _reactor, address _owner) Owned(_owner) {
whitelistedCaller = _whitelistedCaller;
reactor = _reactor;
}
Expand Down