feat: allow to pass msg.sender to USV3 callback
- So that we can possibly do a transferFrom - This should still be safe since the user can't control what is passed here
This commit is contained in:
committed by
Diana Carvalho
parent
389009901e
commit
8969186654
@@ -29,6 +29,7 @@ contract ExecutorTransferMethods {
|
||||
|
||||
function _transfer(
|
||||
IERC20 tokenIn,
|
||||
address sender,
|
||||
address receiver,
|
||||
uint256 amount,
|
||||
TransferMethod method
|
||||
@@ -40,7 +41,7 @@ contract ExecutorTransferMethods {
|
||||
} else if (method == TransferMethod.TRANSFERPERMIT2) {
|
||||
// Permit2.permit is called from the TychoRouter
|
||||
permit2.transferFrom(
|
||||
msg.sender,
|
||||
sender,
|
||||
receiver, // Does this work if receiver is not address(this)?
|
||||
uint160(amount),
|
||||
address(tokenIn)
|
||||
|
||||
@@ -49,7 +49,7 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
|
||||
_verifyPairAddress(target);
|
||||
|
||||
calculatedAmount = _getAmountOut(target, givenAmount, zeroForOne);
|
||||
_transfer(tokenIn, target, givenAmount, method);
|
||||
_transfer(tokenIn, msg.sender, target, givenAmount, method);
|
||||
|
||||
IUniswapV2Pair pool = IUniswapV2Pair(target);
|
||||
if (zeroForOne) {
|
||||
|
||||
@@ -102,14 +102,14 @@ contract UniswapV3Executor is IExecutor, ICallback, ExecutorTransferMethods {
|
||||
"InvalidTransferMethod"
|
||||
);
|
||||
TransferMethod method = TransferMethod(uint8(msgData[171]));
|
||||
address sender = address(bytes20(msgData[172:192]));
|
||||
|
||||
verifyCallback(msgData[132:]);
|
||||
|
||||
uint256 amountOwed =
|
||||
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
||||
|
||||
// TODO This must never be a safeTransfer. Figure out how to ensure this.
|
||||
_transfer(IERC20(tokenIn), msg.sender, amountOwed, method);
|
||||
_transfer(IERC20(tokenIn), sender, msg.sender, amountOwed, method);
|
||||
|
||||
return abi.encode(amountOwed, tokenIn);
|
||||
}
|
||||
@@ -167,7 +167,9 @@ contract UniswapV3Executor is IExecutor, ICallback, ExecutorTransferMethods {
|
||||
uint24 fee,
|
||||
TransferMethod method
|
||||
) internal pure returns (bytes memory) {
|
||||
return abi.encodePacked(tokenIn, tokenOut, fee, uint8(method), self);
|
||||
return abi.encodePacked(
|
||||
tokenIn, tokenOut, fee, uint8(method), msg.sender, self
|
||||
);
|
||||
}
|
||||
|
||||
function _verifyPairAddress(
|
||||
|
||||
@@ -123,7 +123,8 @@ contract UniswapV3ExecutorTest is Test, Constants {
|
||||
dataOffset,
|
||||
dataLength,
|
||||
protocolData,
|
||||
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER)
|
||||
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER),
|
||||
address(uniswapV3Exposed) // transferFrom sender (irrelevant in this case)
|
||||
);
|
||||
uniswapV3Exposed.handleCallback(callbackData);
|
||||
vm.stopPrank();
|
||||
|
||||
Reference in New Issue
Block a user