Files
tycho-execution/foundry/test/executors/UniswapV4Utils.sol
Diana Carvalho 591d73ba71 feat: Support uniswap v4 callback in TychoRouter
Make TychoRouter inherit from SafeCallback and then delegatecall to the UniswapV4 executor
Add a test for this. I had to update the block of our forked network in the tests. Because of this I had to update all the asserts in previous tests

Had to change the optimizer_runs in foundry.toml because of weird Yul errors when compiling

--- don't change below this line ---
ENG-4223 Took 1 hour 21 minutes

Took 7 seconds


Took 35 seconds
2025-02-13 12:00:59 +00:00

47 lines
1.3 KiB
Solidity

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import "@src/executors/UniswapV4Executor.sol";
library UniswapV4Utils {
function encodeExactInputSingle(
address tokenIn,
address tokenOut,
uint24 fee,
bool zeroForOne,
uint24 tickSpacing,
uint128 amountIn
) public pure returns (bytes memory) {
PoolKey memory key = PoolKey({
currency0: Currency.wrap(zeroForOne ? tokenIn : tokenOut),
currency1: Currency.wrap(zeroForOne ? tokenOut : tokenIn),
fee: fee,
tickSpacing: int24(tickSpacing),
hooks: IHooks(address(0))
});
bytes memory actions = abi.encodePacked(
uint8(Actions.SWAP_EXACT_IN_SINGLE),
uint8(Actions.SETTLE_ALL),
uint8(Actions.TAKE_ALL)
);
bytes[] memory params = new bytes[](3);
params[0] = abi.encode(
IV4Router.ExactInputSingleParams({
poolKey: key,
zeroForOne: zeroForOne,
amountIn: amountIn,
amountOutMinimum: 0,
hookData: bytes("")
})
);
params[1] = abi.encode(key.currency0, amountIn);
params[2] = abi.encode(key.currency1, 0);
return abi.encode(actions, params);
}
}