feat: Change signature of _handleCallback to take only bytes calldata

The selector and executor are decoded inside this function now.
For Uniswap V3 I had to manually slice the msg.data from uniswapV3SwapCallback to get the data that matters for the callback

Took 3 hours 12 minutes
This commit is contained in:
Diana Carvalho
2025-02-18 11:11:43 +00:00
parent 2604935609
commit 2aa63d7ec0
4 changed files with 47 additions and 58 deletions

View File

@@ -66,41 +66,23 @@ contract UniswapV3Executor is IExecutor, ICallback {
}
}
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external {
// slither-disable-next-line low-level-calls
(bool success, bytes memory result) = self.delegatecall(
abi.encodeWithSelector(
ICallback.handleCallback.selector,
abi.encodePacked(
amount0Delta, amount1Delta, data[:data.length - 20]
)
)
);
if (!success) {
revert(
string(
result.length > 0
? result
: abi.encodePacked("Callback failed")
)
);
}
}
function handleCallback(bytes calldata msgData)
external
public
returns (bytes memory result)
{
// The data has the following layout:
// - amount0Delta (32 bytes)
// - amount1Delta (32 bytes)
// - dataOffset (32 bytes)
// - dataLength (32 bytes)
// - protocolData (variable length)
(int256 amount0Delta, int256 amount1Delta) =
abi.decode(msgData[:64], (int256, int256));
address tokenIn = address(bytes20(msgData[64:84]));
address tokenIn = address(bytes20(msgData[128:148]));
verifyCallback(msgData[64:]);
verifyCallback(msgData[128:]);
uint256 amountOwed =
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
@@ -118,6 +100,20 @@ contract UniswapV3Executor is IExecutor, ICallback {
CallbackValidationV2.verifyCallback(factory, tokenIn, tokenOut, poolFee);
}
function uniswapV3SwapCallback(
int256, /* amount0Delta */
int256, /* amount1Delta */
bytes calldata /* data */
) external {
uint256 dataOffset = 4 + 32 + 32 + 32; // Skip selector + 2 ints + data_offset
uint256 dataLength =
uint256(bytes32(msg.data[dataOffset:dataOffset + 32]));
bytes calldata fullData = msg.data[4:dataOffset + 32 + dataLength];
handleCallback(fullData);
}
function _decodeData(bytes calldata data)
internal
pure