feat: Implement generic callback

--- don't change below this line ---
ENG-4047 Took 26 minutes


Took 4 minutes

Took 8 seconds

Took 59 seconds

Took 22 seconds
This commit is contained in:
Diana Carvalho
2025-01-28 18:05:10 +00:00
parent e481ceb304
commit fafeba9248
3 changed files with 20 additions and 5 deletions

View File

@@ -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);
}
/**

View File

@@ -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);

View File

@@ -20,7 +20,7 @@ contract TychoRouterExposed is TychoRouter {
return _unwrapETH(amount);
}
function ExposedSwap(
function exposedSwap(
uint256 amountIn,
uint256 nTokens,
bytes calldata swaps