diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index 52b00e1..986f0e4 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -79,7 +79,22 @@ contract TychoRouter is * caller is not a pool. */ fallback() external { - // TODO execute generic callback + _executeGenericCallback(msg.data); + } + + /** + * @dev Check if the sender is correct and executes callback actions. + * @param msgData encoded data. It must includes data for the verification. + */ + function _executeGenericCallback(bytes calldata msgData) internal { + ( + uint256 amountOwed, + uint256 amountReceived, + address tokenOwed, + uint16 offset // I think we actually don't need this! + ) = _callVerifyCallback(msgData); + + IERC20(tokenOwed).safeTransfer(msg.sender, amountOwed); } /** diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index d736494..d1a82c7 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -234,7 +234,7 @@ contract TychoRouterTest is TychoRouterTestSetup { bytes[] memory swaps = new bytes[](1); swaps[0] = swap; - tychoRouter.ExposedSwap(amountIn, 2, pleEncode(swaps)); + tychoRouter.exposedSwap(amountIn, 2, pleEncode(swaps)); uint256 daiBalance = IERC20(DAI_ADDR).balanceOf(tychoRouterAddr); assertEq(daiBalance, 2630432278145144658455); @@ -271,7 +271,7 @@ contract TychoRouterTest is TychoRouterTestSetup { encodeUniswapV2Swap(DAI_ADDR, DAI_USDC_POOL, tychoRouterAddr, true) ); - tychoRouter.ExposedSwap(amountIn, 3, pleEncode(swaps)); + tychoRouter.exposedSwap(amountIn, 3, pleEncode(swaps)); uint256 usdcBalance = IERC20(USDC_ADDR).balanceOf(tychoRouterAddr); assertEq(usdcBalance, 2610580090); @@ -332,7 +332,7 @@ contract TychoRouterTest is TychoRouterTestSetup { encodeUniswapV2Swap(DAI_ADDR, DAI_USDC_POOL, tychoRouterAddr, true) ); - tychoRouter.ExposedSwap(amountIn, 4, pleEncode(swaps)); + tychoRouter.exposedSwap(amountIn, 4, pleEncode(swaps)); uint256 usdcBalance = IERC20(USDC_ADDR).balanceOf(tychoRouterAddr); assertEq(usdcBalance, 2581503157); diff --git a/foundry/test/TychoRouterTestSetup.sol b/foundry/test/TychoRouterTestSetup.sol index a4404c0..97b653d 100644 --- a/foundry/test/TychoRouterTestSetup.sol +++ b/foundry/test/TychoRouterTestSetup.sol @@ -20,7 +20,7 @@ contract TychoRouterExposed is TychoRouter { return _unwrapETH(amount); } - function ExposedSwap( + function exposedSwap( uint256 amountIn, uint256 nTokens, bytes calldata swaps