feat: hardcode callback and swap selection in dispatcher
This commit is contained in:
@@ -55,7 +55,6 @@ contract Dispatcher {
|
||||
// slither-disable-next-line delegatecall-loop
|
||||
function _callExecutor(
|
||||
address executor,
|
||||
bytes4 selector,
|
||||
uint256 amount,
|
||||
bytes calldata data
|
||||
) internal returns (uint256 calculatedAmount) {
|
||||
@@ -63,10 +62,9 @@ contract Dispatcher {
|
||||
revert Dispatcher__UnapprovedExecutor();
|
||||
}
|
||||
|
||||
selector = selector == bytes4(0) ? IExecutor.swap.selector : selector;
|
||||
// slither-disable-next-line controlled-delegatecall,low-level-calls
|
||||
(bool success, bytes memory result) = executor.delegatecall(
|
||||
abi.encodeWithSelector(selector, amount, data)
|
||||
abi.encodeWithSelector(IExecutor.swap.selector, amount, data)
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
@@ -83,18 +81,16 @@ contract Dispatcher {
|
||||
}
|
||||
|
||||
function _handleCallback(bytes calldata data) internal {
|
||||
bytes4 selector = bytes4(data[data.length - 4:]);
|
||||
address executor = address(uint160(bytes20(data[data.length - 24:])));
|
||||
|
||||
if (!executors[executor]) {
|
||||
revert Dispatcher__UnapprovedExecutor();
|
||||
}
|
||||
|
||||
selector =
|
||||
selector == bytes4(0) ? ICallback.handleCallback.selector : selector;
|
||||
// slither-disable-next-line controlled-delegatecall,low-level-calls
|
||||
(bool success, bytes memory result) =
|
||||
executor.delegatecall(abi.encodeWithSelector(selector, data));
|
||||
(bool success, bytes memory result) = executor.delegatecall(
|
||||
abi.encodeWithSelector(ICallback.handleCallback.selector, data)
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
revert(
|
||||
|
||||
@@ -286,10 +286,7 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
: remainingAmounts[tokenInIndex];
|
||||
|
||||
currentAmountOut = _callExecutor(
|
||||
swapData.executor(),
|
||||
swapData.executorSelector(),
|
||||
currentAmountIn,
|
||||
swapData.protocolData()
|
||||
swapData.executor(), currentAmountIn, swapData.protocolData()
|
||||
);
|
||||
amounts[tokenOutIndex] += currentAmountOut;
|
||||
remainingAmounts[tokenOutIndex] += currentAmountOut;
|
||||
|
||||
@@ -16,10 +16,11 @@ import {V4Router} from "@uniswap/v4-periphery/src/V4Router.sol";
|
||||
import {Actions} from "@uniswap/v4-periphery/src/libraries/Actions.sol";
|
||||
import {IV4Router} from "@uniswap/v4-periphery/src/interfaces/IV4Router.sol";
|
||||
import {PathKey} from "@uniswap/v4-periphery/src/libraries/PathKey.sol";
|
||||
import {ICallback} from "@interfaces/ICallback.sol";
|
||||
|
||||
error UniswapV4Executor__InvalidDataLength();
|
||||
|
||||
contract UniswapV4Executor is IExecutor, V4Router {
|
||||
contract UniswapV4Executor is IExecutor, V4Router, ICallback {
|
||||
using SafeERC20 for IERC20;
|
||||
using CurrencyLibrary for Currency;
|
||||
|
||||
@@ -176,6 +177,16 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
||||
}
|
||||
}
|
||||
|
||||
function handleCallback(bytes calldata data)
|
||||
external
|
||||
returns (bytes memory)
|
||||
{
|
||||
verifyCallback(data);
|
||||
return _unlockCallback(data);
|
||||
}
|
||||
|
||||
function verifyCallback(bytes calldata) public view onlyPoolManager {}
|
||||
|
||||
function _pay(Currency token, address, uint256 amount) internal override {
|
||||
IERC20(Currency.unwrap(token)).safeTransfer(
|
||||
address(poolManager), amount
|
||||
|
||||
Reference in New Issue
Block a user