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(
|
function _transfer(
|
||||||
IERC20 tokenIn,
|
IERC20 tokenIn,
|
||||||
|
address sender,
|
||||||
address receiver,
|
address receiver,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
TransferMethod method
|
TransferMethod method
|
||||||
@@ -40,7 +41,7 @@ contract ExecutorTransferMethods {
|
|||||||
} else if (method == TransferMethod.TRANSFERPERMIT2) {
|
} else if (method == TransferMethod.TRANSFERPERMIT2) {
|
||||||
// Permit2.permit is called from the TychoRouter
|
// Permit2.permit is called from the TychoRouter
|
||||||
permit2.transferFrom(
|
permit2.transferFrom(
|
||||||
msg.sender,
|
sender,
|
||||||
receiver, // Does this work if receiver is not address(this)?
|
receiver, // Does this work if receiver is not address(this)?
|
||||||
uint160(amount),
|
uint160(amount),
|
||||||
address(tokenIn)
|
address(tokenIn)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
|
|||||||
_verifyPairAddress(target);
|
_verifyPairAddress(target);
|
||||||
|
|
||||||
calculatedAmount = _getAmountOut(target, givenAmount, zeroForOne);
|
calculatedAmount = _getAmountOut(target, givenAmount, zeroForOne);
|
||||||
_transfer(tokenIn, target, givenAmount, method);
|
_transfer(tokenIn, msg.sender, target, givenAmount, method);
|
||||||
|
|
||||||
IUniswapV2Pair pool = IUniswapV2Pair(target);
|
IUniswapV2Pair pool = IUniswapV2Pair(target);
|
||||||
if (zeroForOne) {
|
if (zeroForOne) {
|
||||||
|
|||||||
@@ -102,14 +102,14 @@ contract UniswapV3Executor is IExecutor, ICallback, ExecutorTransferMethods {
|
|||||||
"InvalidTransferMethod"
|
"InvalidTransferMethod"
|
||||||
);
|
);
|
||||||
TransferMethod method = TransferMethod(uint8(msgData[171]));
|
TransferMethod method = TransferMethod(uint8(msgData[171]));
|
||||||
|
address sender = address(bytes20(msgData[172:192]));
|
||||||
|
|
||||||
verifyCallback(msgData[132:]);
|
verifyCallback(msgData[132:]);
|
||||||
|
|
||||||
uint256 amountOwed =
|
uint256 amountOwed =
|
||||||
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
||||||
|
|
||||||
// TODO This must never be a safeTransfer. Figure out how to ensure this.
|
_transfer(IERC20(tokenIn), sender, msg.sender, amountOwed, method);
|
||||||
_transfer(IERC20(tokenIn), msg.sender, amountOwed, method);
|
|
||||||
|
|
||||||
return abi.encode(amountOwed, tokenIn);
|
return abi.encode(amountOwed, tokenIn);
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,9 @@ contract UniswapV3Executor is IExecutor, ICallback, ExecutorTransferMethods {
|
|||||||
uint24 fee,
|
uint24 fee,
|
||||||
TransferMethod method
|
TransferMethod method
|
||||||
) internal pure returns (bytes memory) {
|
) 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(
|
function _verifyPairAddress(
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ contract UniswapV3ExecutorTest is Test, Constants {
|
|||||||
dataOffset,
|
dataOffset,
|
||||||
dataLength,
|
dataLength,
|
||||||
protocolData,
|
protocolData,
|
||||||
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER)
|
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER),
|
||||||
|
address(uniswapV3Exposed) // transferFrom sender (irrelevant in this case)
|
||||||
);
|
);
|
||||||
uniswapV3Exposed.handleCallback(callbackData);
|
uniswapV3Exposed.handleCallback(callbackData);
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|||||||
Reference in New Issue
Block a user