feat: rename execution dispatcher to dispatcher and use dispatcher for USV4 callback
This commit is contained in:
@@ -5,11 +5,11 @@ import "@interfaces/IExecutor.sol";
|
||||
import "@interfaces/ICallback.sol";
|
||||
import "forge-std/console.sol";
|
||||
|
||||
error ExecutionDispatcher__UnapprovedExecutor();
|
||||
error ExecutionDispatcher__NonContractExecutor();
|
||||
error Dispatcher__UnapprovedExecutor();
|
||||
error Dispatcher__NonContractExecutor();
|
||||
|
||||
/**
|
||||
* @title ExecutionDispatcher - Dispatch execution to external contracts
|
||||
* @title Dispatcher - Dispatch execution to external contracts
|
||||
* @author PropellerHeads Devs
|
||||
* @dev Provides the ability to delegate execution of swaps to external
|
||||
* contracts. This allows dynamically adding new supported protocols
|
||||
@@ -20,7 +20,7 @@ error ExecutionDispatcher__NonContractExecutor();
|
||||
* Note: Executor contracts need to implement the IExecutor interface unless
|
||||
* an alternate selector is specified.
|
||||
*/
|
||||
contract ExecutionDispatcher {
|
||||
contract Dispatcher {
|
||||
mapping(address => bool) public executors;
|
||||
|
||||
event ExecutorSet(address indexed executor);
|
||||
@@ -33,7 +33,7 @@ contract ExecutionDispatcher {
|
||||
*/
|
||||
function _setExecutor(address target) internal {
|
||||
if (target.code.length == 0) {
|
||||
revert ExecutionDispatcher__NonContractExecutor();
|
||||
revert Dispatcher__NonContractExecutor();
|
||||
}
|
||||
executors[target] = true;
|
||||
emit ExecutorSet(target);
|
||||
@@ -60,7 +60,7 @@ contract ExecutionDispatcher {
|
||||
bytes calldata data
|
||||
) internal returns (uint256 calculatedAmount) {
|
||||
if (!executors[executor]) {
|
||||
revert ExecutionDispatcher__UnapprovedExecutor();
|
||||
revert Dispatcher__UnapprovedExecutor();
|
||||
}
|
||||
|
||||
selector = selector == bytes4(0) ? IExecutor.swap.selector : selector;
|
||||
@@ -93,7 +93,7 @@ contract ExecutionDispatcher {
|
||||
}
|
||||
|
||||
if (!executors[executor]) {
|
||||
revert ExecutionDispatcher__UnapprovedExecutor();
|
||||
revert Dispatcher__UnapprovedExecutor();
|
||||
}
|
||||
|
||||
selector =
|
||||
@@ -11,11 +11,10 @@ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||
import "@openzeppelin/contracts/utils/Pausable.sol";
|
||||
import "@openzeppelin/contracts/utils/Address.sol";
|
||||
import "@permit2/src/interfaces/IAllowanceTransfer.sol";
|
||||
import "./ExecutionDispatcher.sol";
|
||||
import "./Dispatcher.sol";
|
||||
import {LibSwap} from "../lib/LibSwap.sol";
|
||||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
||||
import {SafeCallback} from "@uniswap/v4-periphery/src/base/SafeCallback.sol";
|
||||
import "forge-std/console.sol";
|
||||
|
||||
error TychoRouter__WithdrawalFailed();
|
||||
error TychoRouter__AddressZero();
|
||||
@@ -26,7 +25,7 @@ error TychoRouter__MessageValueMismatch(uint256 value, uint256 amount);
|
||||
|
||||
contract TychoRouter is
|
||||
AccessControl,
|
||||
ExecutionDispatcher,
|
||||
Dispatcher,
|
||||
Pausable,
|
||||
ReentrancyGuard,
|
||||
SafeCallback
|
||||
@@ -390,16 +389,7 @@ contract TychoRouter is
|
||||
bytes4 selector = bytes4(data[data.length - 24:data.length - 20]);
|
||||
address executor = address(uint160(bytes20(data[data.length - 20:])));
|
||||
bytes memory protocolData = data[:data.length - 24];
|
||||
|
||||
if (!executors[executor]) {
|
||||
revert ExecutionDispatcher__UnapprovedExecutor();
|
||||
}
|
||||
|
||||
// slither-disable-next-line controlled-delegatecall,low-level-calls
|
||||
(bool success,) = executor.delegatecall(
|
||||
abi.encodeWithSelector(selector, protocolData)
|
||||
);
|
||||
require(success, "delegatecall to uniswap v4 callback failed");
|
||||
_handleCallback(selector, abi.encodePacked(protocolData, executor));
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user