- For protocols like Balancer and Curve, which expect funds to be in the router at the time of swap, we must support also transferring funds from the user into the router. Doing this in the router would mean we are dealing with transfers in two different places: in the router main methods and in the executors. To avoid this, we are now performing transfers just in the executors, and two transfer types have been added to support transfers into the router. TODO: - Add this for Balancer and Curve (only added for USV4 atm). - TODO consider renaming TRANSFER_FROM and TRANSFER_PERMIT2 to include "pool" in the name
34 lines
873 B
Solidity
34 lines
873 B
Solidity
// SPDX-License-Identifier: BUSL-1.1
|
|
pragma solidity ^0.8.26;
|
|
|
|
import "@src/executors/UniswapV4Executor.sol";
|
|
|
|
library UniswapV4Utils {
|
|
function encodeExactInput(
|
|
address tokenIn,
|
|
address tokenOut,
|
|
bool zeroForOne,
|
|
UniswapV4Executor.TransferType transferType,
|
|
UniswapV4Executor.UniswapV4Pool[] memory pools
|
|
) public pure returns (bytes memory) {
|
|
bytes memory encodedPools;
|
|
|
|
for (uint256 i = 0; i < pools.length; i++) {
|
|
encodedPools = abi.encodePacked(
|
|
encodedPools,
|
|
pools[i].intermediaryToken,
|
|
bytes3(pools[i].fee),
|
|
pools[i].tickSpacing
|
|
);
|
|
}
|
|
|
|
return abi.encodePacked(
|
|
tokenIn,
|
|
tokenOut,
|
|
zeroForOne,
|
|
transferType,
|
|
encodedPools
|
|
);
|
|
}
|
|
}
|