feat(univ4): Pass user_data as hook_data in execution

Because we don't know the size of hook data, it needs to be at the end of the protocol data. But we also don't know the size of the intermediary swaps. To solve this, we are now ple encoding the intermediary swaps and only then appending the hook data

Took 2 hours 50 minutes

Took 40 seconds
This commit is contained in:
Diana Carvalho
2025-06-18 15:53:30 +01:00
committed by Diana Carvalho
parent a0581773cd
commit 93678d9d19
6 changed files with 159 additions and 49 deletions

View File

@@ -25,6 +25,7 @@ contract UniswapV4ExecutorExposed is UniswapV4Executor {
RestrictTransferFrom.TransferType transferType,
address receiver,
address hook,
bytes memory hookData,
UniswapV4Pool[] memory pools
)
{
@@ -77,6 +78,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
RestrictTransferFrom.TransferType.Transfer,
ALICE,
address(0),
bytes(""),
pools
);
@@ -87,6 +89,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
RestrictTransferFrom.TransferType transferType,
address receiver,
address hook,
bytes memory hookData,
UniswapV4Executor.UniswapV4Pool[] memory decodedPools
) = uniswapV4Exposed.decodeData(data);
@@ -130,6 +133,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
RestrictTransferFrom.TransferType.Transfer,
ALICE,
address(0),
bytes(""),
pools
);
@@ -188,6 +192,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
RestrictTransferFrom.TransferType.Transfer,
ALICE,
address(0),
bytes(""),
pools
);
@@ -244,6 +249,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
RestrictTransferFrom.TransferType.Transfer,
ALICE,
hook,
bytes(""),
pools
);

View File

@@ -11,13 +11,20 @@ library UniswapV4Utils {
RestrictTransferFrom.TransferType transferType,
address receiver,
address hook,
bytes memory hookData,
UniswapV4Executor.UniswapV4Pool[] memory pools
) public pure returns (bytes memory) {
bytes memory encodedPools;
require(pools.length > 0, "Must have at least one pool");
for (uint256 i = 0; i < pools.length; i++) {
encodedPools = abi.encodePacked(
encodedPools,
bytes memory firstPool = abi.encodePacked(
pools[0].intermediaryToken,
bytes3(pools[0].fee),
pools[0].tickSpacing
);
bytes[] memory encodedExtraPools = new bytes[](pools.length - 1);
for (uint256 i = 1; i < pools.length; i++) {
encodedExtraPools[i - 1] = abi.encodePacked(
pools[i].intermediaryToken,
bytes3(pools[i].fee),
pools[i].tickSpacing
@@ -31,7 +38,22 @@ library UniswapV4Utils {
transferType,
receiver,
hook,
encodedPools
firstPool,
pleEncode(encodedExtraPools),
hookData
);
}
function pleEncode(bytes[] memory data)
public
pure
returns (bytes memory encoded)
{
for (uint256 i = 0; i < data.length; i++) {
encoded = bytes.concat(
encoded,
abi.encodePacked(bytes2(uint16(data[i].length)), data[i])
);
}
}
}