feat: update _handleCallback, add verifyCallback with docs
This commit is contained in:
@@ -29,11 +29,10 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
}
|
||||
|
||||
// slither-disable-next-line locked-ether
|
||||
function swap(uint256 amountIn, bytes calldata data)
|
||||
external
|
||||
payable
|
||||
returns (uint256 amountOut)
|
||||
{
|
||||
function swap(
|
||||
uint256 amountIn,
|
||||
bytes calldata data
|
||||
) external payable returns (uint256 amountOut) {
|
||||
(
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
@@ -76,7 +75,9 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
abi.encodeWithSelector(
|
||||
ICallback.handleCallback.selector,
|
||||
abi.encodePacked(
|
||||
amount0Delta, amount1Delta, data[:data.length - 20]
|
||||
amount0Delta,
|
||||
amount1Delta,
|
||||
data[:data.length - 20]
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -91,28 +92,43 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
}
|
||||
}
|
||||
|
||||
function handleCallback(bytes calldata msgData)
|
||||
external
|
||||
returns (bytes memory result)
|
||||
{
|
||||
(int256 amount0Delta, int256 amount1Delta) =
|
||||
abi.decode(msgData[:64], (int256, int256));
|
||||
function handleCallback(
|
||||
bytes calldata msgData
|
||||
) external returns (bytes memory result) {
|
||||
(int256 amount0Delta, int256 amount1Delta) = abi.decode(
|
||||
msgData[:64],
|
||||
(int256, int256)
|
||||
);
|
||||
|
||||
address tokenIn = address(bytes20(msgData[64:84]));
|
||||
address tokenOut = address(bytes20(msgData[84:104]));
|
||||
uint24 poolFee = uint24(bytes3(msgData[104:107]));
|
||||
|
||||
// slither-disable-next-line unused-return
|
||||
CallbackValidationV2.verifyCallback(factory, tokenIn, tokenOut, poolFee);
|
||||
verifyCallback(msgData[64:]);
|
||||
|
||||
uint256 amountOwed =
|
||||
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
||||
uint256 amountOwed = amount0Delta > 0
|
||||
? uint256(amount0Delta)
|
||||
: uint256(amount1Delta);
|
||||
|
||||
IERC20(tokenIn).safeTransfer(msg.sender, amountOwed);
|
||||
return abi.encode(amountOwed, tokenIn);
|
||||
}
|
||||
|
||||
function _decodeData(bytes calldata data)
|
||||
function verifyCallback(bytes calldata data) public view {
|
||||
address tokenIn = address(bytes20(data[0:20]));
|
||||
address tokenOut = address(bytes20(data[20:40]));
|
||||
uint24 poolFee = uint24(bytes3(data[40:43]));
|
||||
|
||||
// slither-disable-next-line unused-return
|
||||
CallbackValidationV2.verifyCallback(
|
||||
factory,
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
poolFee
|
||||
);
|
||||
}
|
||||
|
||||
function _decodeData(
|
||||
bytes calldata data
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (
|
||||
@@ -135,11 +151,18 @@ contract UniswapV3Executor is IExecutor, ICallback {
|
||||
zeroForOne = uint8(data[83]) > 0;
|
||||
}
|
||||
|
||||
function _makeV3CallbackData(address tokenIn, address tokenOut, uint24 fee)
|
||||
internal
|
||||
view
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodePacked(tokenIn, tokenOut, fee, self);
|
||||
function _makeV3CallbackData(
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
uint24 fee
|
||||
) internal view returns (bytes memory) {
|
||||
return
|
||||
abi.encodePacked(
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
fee,
|
||||
ICallback.handleCallback.selector,
|
||||
self
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user