feat: Proper USV2Executor transfer decoding + tests

- Properly decode, update tests with proper decoding
- Added test case for each transfer method
- Also fully tested permit2 transferFrom and it works perfectly.

TODO:
- Fix integration tests once encoding is implemented.
This commit is contained in:
TAMARA LIPOWSKI
2025-04-07 20:42:54 -04:00
committed by Diana Carvalho
parent 8969186654
commit ca1d474f08
5 changed files with 216 additions and 24 deletions

View File

@@ -14,9 +14,13 @@ contract ExecutorTransferMethods {
IAllowanceTransfer public immutable permit2;
enum TransferMethod {
// Assume funds are in the TychoRouter - transfer into the pool
TRANSFER,
// Assume funds are in msg.sender's wallet - transferFrom into the pool
TRANSFERFROM,
// Assume funds are in msg.sender's wallet - permit2TransferFrom into the pool
TRANSFERPERMIT2,
// Assume funds have already been transferred into the pool. Do nothing.
NONE
}
@@ -39,10 +43,10 @@ contract ExecutorTransferMethods {
} else if (method == TransferMethod.TRANSFERFROM) {
tokenIn.safeTransferFrom(msg.sender, receiver, amount);
} else if (method == TransferMethod.TRANSFERPERMIT2) {
// Permit2.permit is called from the TychoRouter
// Permit2.permit is already called from the TychoRouter
permit2.transferFrom(
sender,
receiver, // Does this work if receiver is not address(this)?
receiver,
uint160(amount),
address(tokenIn)
);

View File

@@ -70,15 +70,14 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
TransferMethod method
)
{
if (data.length != 61) {
if (data.length != 62) {
revert UniswapV2Executor__InvalidDataLength();
}
inToken = IERC20(address(bytes20(data[0:20])));
target = address(bytes20(data[20:40]));
receiver = address(bytes20(data[40:60]));
zeroForOne = uint8(data[60]) > 0;
// TODO properly decode, assume encoded using just 1 byte.
method = TransferMethod.TRANSFER;
method = TransferMethod(uint8(data[61]));
}
function _getAmountOut(address target, uint256 amountIn, bool zeroForOne)