feat: move callback testing to usv3 executor
This commit is contained in:
@@ -626,24 +626,6 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
// function testUSV3Callback() public {
|
||||
// uint24 poolFee = 3000;
|
||||
// uint256 amountOwed = 1000000000000000000;
|
||||
// deal(WETH_ADDR, tychoRouterAddr, amountOwed);
|
||||
// uint256 initialPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
||||
|
||||
// vm.startPrank(DAI_WETH_USV3);
|
||||
// tychoRouter.uniswapV3SwapCallback(
|
||||
// -2631245338449998525223,
|
||||
// int256(amountOwed),
|
||||
// abi.encodePacked(WETH_ADDR, DAI_ADDR, poolFee)
|
||||
// );
|
||||
// vm.stopPrank();
|
||||
|
||||
// uint256 finalPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
||||
// assertEq(finalPoolReserve - initialPoolReserve, amountOwed);
|
||||
// }
|
||||
|
||||
function testSwapSingleUSV3() public {
|
||||
// Trade 1 WETH for DAI with 1 swap on Uniswap V3
|
||||
// 1 WETH -> DAI
|
||||
|
||||
@@ -69,4 +69,48 @@ contract UniswapV3ExecutorTest is Test, Constants {
|
||||
vm.expectRevert(UniswapV3Executor__InvalidDataLength.selector);
|
||||
uniswapV3Exposed.decodeData(invalidParams);
|
||||
}
|
||||
|
||||
function testUSV3Callback() public {
|
||||
uint24 poolFee = 3000;
|
||||
uint256 amountOwed = 1000000000000000000;
|
||||
deal(WETH_ADDR, address(uniswapV3Exposed), amountOwed);
|
||||
uint256 initialPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
||||
|
||||
vm.startPrank(DAI_WETH_USV3);
|
||||
bytes memory callbackData = _encodeUSV3CallbackData(
|
||||
int256(amountOwed), // amount0Delta
|
||||
int256(0), // amount1Delta
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
poolFee
|
||||
);
|
||||
uniswapV3Exposed.handleCallback(callbackData);
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 finalPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
||||
assertEq(finalPoolReserve - initialPoolReserve, amountOwed);
|
||||
}
|
||||
|
||||
function _encodeUSV3CallbackData(
|
||||
int256 amount0Delta,
|
||||
int256 amount1Delta,
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
uint24 fee
|
||||
) internal pure returns (bytes memory) {
|
||||
// Dummy selector for handleCallback
|
||||
bytes4 selector =
|
||||
bytes4(keccak256("handleCallback(int256,int256,bytes)"));
|
||||
|
||||
bytes memory tokenData = abi.encodePacked(tokenIn, tokenOut, fee);
|
||||
|
||||
// [0:4] - function selector
|
||||
// [4:68] - abi.encode(amount0Delta, amount1Delta)
|
||||
// [68:end] - abi.encode(tokenData) where tokenData is the packed bytes
|
||||
return abi.encodePacked(
|
||||
selector,
|
||||
abi.encode(amount0Delta, amount1Delta),
|
||||
abi.encode(tokenData)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user