chore: update unlockCallback and uniswapV3SwapCallback
This commit is contained in:
@@ -370,8 +370,8 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
|||||||
bytes calldata data
|
bytes calldata data
|
||||||
) external {
|
) external {
|
||||||
if (data.length < 24) revert TychoRouter__InvalidDataLength();
|
if (data.length < 24) revert TychoRouter__InvalidDataLength();
|
||||||
address executor = address(uint160(bytes20(data[data.length - 20:])));
|
bytes4 selector = bytes4(data[data.length - 4:]);
|
||||||
bytes4 selector = bytes4(data[data.length - 24:data.length - 20]);
|
address executor = address(uint160(bytes20(data[data.length - 24:])));
|
||||||
bytes memory protocolData = data[:data.length - 24];
|
bytes memory protocolData = data[:data.length - 24];
|
||||||
_handleCallback(
|
_handleCallback(
|
||||||
selector,
|
selector,
|
||||||
@@ -388,8 +388,9 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
|||||||
returns (bytes memory)
|
returns (bytes memory)
|
||||||
{
|
{
|
||||||
if (data.length < 24) revert TychoRouter__InvalidDataLength();
|
if (data.length < 24) revert TychoRouter__InvalidDataLength();
|
||||||
address executor = address(uint160(bytes20(data[data.length - 20:])));
|
bytes4 selector = bytes4(data[data.length - 4:]);
|
||||||
bytes4 selector = bytes4(data[data.length - 24:data.length - 20]);
|
address executor =
|
||||||
|
address(uint160(bytes20(data[data.length - 24:data.length - 4])));
|
||||||
bytes memory protocolData = data[:data.length - 24];
|
bytes memory protocolData = data[:data.length - 24];
|
||||||
_handleCallback(selector, executor, protocolData);
|
_handleCallback(selector, executor, protocolData);
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -29,10 +29,11 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// slither-disable-next-line locked-ether
|
// slither-disable-next-line locked-ether
|
||||||
function swap(
|
function swap(uint256 amountIn, bytes calldata data)
|
||||||
uint256 amountIn,
|
external
|
||||||
bytes calldata data
|
payable
|
||||||
) external payable returns (uint256 amountOut) {
|
returns (uint256 amountOut)
|
||||||
|
{
|
||||||
(
|
(
|
||||||
address tokenIn,
|
address tokenIn,
|
||||||
address tokenOut,
|
address tokenOut,
|
||||||
@@ -75,9 +76,7 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
|||||||
abi.encodeWithSelector(
|
abi.encodeWithSelector(
|
||||||
ICallback.handleCallback.selector,
|
ICallback.handleCallback.selector,
|
||||||
abi.encodePacked(
|
abi.encodePacked(
|
||||||
amount0Delta,
|
amount0Delta, amount1Delta, data[:data.length - 20]
|
||||||
amount1Delta,
|
|
||||||
data[:data.length - 20]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -92,21 +91,19 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCallback(
|
function handleCallback(bytes calldata msgData)
|
||||||
bytes calldata msgData
|
external
|
||||||
) external returns (bytes memory result) {
|
returns (bytes memory result)
|
||||||
(int256 amount0Delta, int256 amount1Delta) = abi.decode(
|
{
|
||||||
msgData[:64],
|
(int256 amount0Delta, int256 amount1Delta) =
|
||||||
(int256, int256)
|
abi.decode(msgData[:64], (int256, int256));
|
||||||
);
|
|
||||||
|
|
||||||
address tokenIn = address(bytes20(msgData[64:84]));
|
address tokenIn = address(bytes20(msgData[64:84]));
|
||||||
|
|
||||||
verifyCallback(msgData[64:]);
|
verifyCallback(msgData[64:]);
|
||||||
|
|
||||||
uint256 amountOwed = amount0Delta > 0
|
uint256 amountOwed =
|
||||||
? uint256(amount0Delta)
|
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
||||||
: uint256(amount1Delta);
|
|
||||||
|
|
||||||
IERC20(tokenIn).safeTransfer(msg.sender, amountOwed);
|
IERC20(tokenIn).safeTransfer(msg.sender, amountOwed);
|
||||||
return abi.encode(amountOwed, tokenIn);
|
return abi.encode(amountOwed, tokenIn);
|
||||||
@@ -118,17 +115,10 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
|||||||
uint24 poolFee = uint24(bytes3(data[40:43]));
|
uint24 poolFee = uint24(bytes3(data[40:43]));
|
||||||
|
|
||||||
// slither-disable-next-line unused-return
|
// slither-disable-next-line unused-return
|
||||||
CallbackValidationV2.verifyCallback(
|
CallbackValidationV2.verifyCallback(factory, tokenIn, tokenOut, poolFee);
|
||||||
factory,
|
|
||||||
tokenIn,
|
|
||||||
tokenOut,
|
|
||||||
poolFee
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _decodeData(
|
function _decodeData(bytes calldata data)
|
||||||
bytes calldata data
|
|
||||||
)
|
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
@@ -151,18 +141,13 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
|||||||
zeroForOne = uint8(data[83]) > 0;
|
zeroForOne = uint8(data[83]) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _makeV3CallbackData(
|
function _makeV3CallbackData(address tokenIn, address tokenOut, uint24 fee)
|
||||||
address tokenIn,
|
internal
|
||||||
address tokenOut,
|
view
|
||||||
uint24 fee
|
returns (bytes memory)
|
||||||
) internal view returns (bytes memory) {
|
{
|
||||||
return
|
return abi.encodePacked(
|
||||||
abi.encodePacked(
|
tokenIn, tokenOut, fee, self, ICallback.handleCallback.selector
|
||||||
tokenIn,
|
);
|
||||||
tokenOut,
|
|
||||||
fee,
|
|
||||||
ICallback.handleCallback.selector,
|
|
||||||
self
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {Actions} from "@uniswap/v4-periphery/src/libraries/Actions.sol";
|
|||||||
import {IV4Router} from "@uniswap/v4-periphery/src/interfaces/IV4Router.sol";
|
import {IV4Router} from "@uniswap/v4-periphery/src/interfaces/IV4Router.sol";
|
||||||
import {PathKey} from "@uniswap/v4-periphery/src/libraries/PathKey.sol";
|
import {PathKey} from "@uniswap/v4-periphery/src/libraries/PathKey.sol";
|
||||||
|
|
||||||
|
|
||||||
error UniswapV4Executor__InvalidDataLength();
|
error UniswapV4Executor__InvalidDataLength();
|
||||||
|
|
||||||
contract UniswapV4Executor is IExecutor, V4Router {
|
contract UniswapV4Executor is IExecutor, V4Router {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import "@src/executors/UniswapV4Executor.sol";
|
|||||||
import {TychoRouter} from "@src/TychoRouter.sol";
|
import {TychoRouter} from "@src/TychoRouter.sol";
|
||||||
import "./TychoRouterTestSetup.sol";
|
import "./TychoRouterTestSetup.sol";
|
||||||
import "./executors/UniswapV4Utils.sol";
|
import "./executors/UniswapV4Utils.sol";
|
||||||
|
import {SafeCallback} from "@uniswap/v4-periphery/src/base/SafeCallback.sol";
|
||||||
|
|
||||||
contract TychoRouterTest is TychoRouterTestSetup {
|
contract TychoRouterTest is TychoRouterTestSetup {
|
||||||
bytes32 public constant EXECUTOR_SETTER_ROLE =
|
bytes32 public constant EXECUTOR_SETTER_ROLE =
|
||||||
|
|||||||
Reference in New Issue
Block a user