feat: USV3 verification
This commit is contained in:
@@ -59,10 +59,13 @@ contract TychoRouter is
|
||||
);
|
||||
event FeeSet(uint256 indexed oldFee, uint256 indexed newFee);
|
||||
|
||||
constructor(address _permit2, address weth) {
|
||||
address private immutable _usv3Factory;
|
||||
|
||||
constructor(address _permit2, address weth, address usv3Factory) {
|
||||
permit2 = IAllowanceTransfer(_permit2);
|
||||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
||||
_weth = IWETH(weth);
|
||||
_usv3Factory = usv3Factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,4 +343,41 @@ contract TychoRouter is
|
||||
* @dev Allows this contract to receive native token
|
||||
*/
|
||||
receive() external payable {}
|
||||
|
||||
/**
|
||||
* @dev Called by UniswapV3 pool when swapping on it.
|
||||
* See in IUniswapV3SwapCallback for documentation.
|
||||
*/
|
||||
function uniswapV3SwapCallback(
|
||||
int256 amount0Delta,
|
||||
int256 amount1Delta,
|
||||
bytes calldata msgData
|
||||
) external {
|
||||
(uint256 amountOwed, address tokenOwed) =
|
||||
_verifyUSV3Callback(amount0Delta, amount1Delta, msgData);
|
||||
IERC20(tokenOwed).safeTransfer(msg.sender, amountOwed);
|
||||
}
|
||||
|
||||
function _verifyUSV3Callback(
|
||||
int256 amount0Delta,
|
||||
int256 amount1Delta,
|
||||
bytes calldata data
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (uint256 amountOwed, address tokenOwed)
|
||||
{
|
||||
address tokenIn = address(bytes20(data[0:20]));
|
||||
address tokenOut = address(bytes20(data[20:40]));
|
||||
uint24 fee = uint24(bytes3(data[40:43]));
|
||||
|
||||
CallbackValidationV2.verifyCallback(
|
||||
_usv3Factory, tokenIn, tokenOut, fee
|
||||
);
|
||||
|
||||
amountOwed =
|
||||
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
||||
|
||||
return (amountOwed, tokenOwed);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user