@@ -31,6 +31,18 @@ interface IUniswapV3Router {
3131 function exactInput (ExactInputParams memory params ) external payable returns (uint256 amountOut );
3232}
3333
34+ // https://github.com/Uniswap/swap-router-contracts/blob/main/contracts/interfaces/IV3SwapRouter.sol
35+ interface IUniswapV3Router2 {
36+ struct ExactInputParams {
37+ bytes path;
38+ address recipient;
39+ uint256 amountIn;
40+ uint256 amountOutMinimum;
41+ }
42+
43+ function exactInput (ExactInputParams memory params ) external payable returns (uint256 amountOut );
44+ }
45+
3446contract MixinUniswapV3 {
3547 using LibERC20TokenV06 for IERC20Token ;
3648
@@ -39,19 +51,30 @@ contract MixinUniswapV3 {
3951 uint256 sellAmount ,
4052 bytes memory bridgeData
4153 ) internal returns (uint256 boughtAmount ) {
42- (IUniswapV3Router router , bytes memory path ) = abi.decode (bridgeData, (IUniswapV3Router , bytes ));
54+ (address router , bytes memory path , uint256 routerVersion ) = abi.decode (bridgeData, (address , bytes , uint256 ));
4355
4456 // Grant the Uniswap router an allowance to sell the sell token.
45- sellToken.approveIfBelow (address (router), sellAmount);
46-
47- boughtAmount = router.exactInput (
48- IUniswapV3Router.ExactInputParams ({
49- path: path,
50- recipient: address (this ),
51- deadline: block .timestamp ,
52- amountIn: sellAmount,
53- amountOutMinimum: 1
54- })
55- );
57+ sellToken.approveIfBelow (router, sellAmount);
58+
59+ if (routerVersion != 2 ) {
60+ boughtAmount = IUniswapV3Router (router).exactInput (
61+ IUniswapV3Router.ExactInputParams ({
62+ path: path,
63+ recipient: address (this ),
64+ deadline: block .timestamp ,
65+ amountIn: sellAmount,
66+ amountOutMinimum: 1
67+ })
68+ );
69+ } else {
70+ boughtAmount = IUniswapV3Router2 (router).exactInput (
71+ IUniswapV3Router2.ExactInputParams ({
72+ path: path,
73+ recipient: address (this ),
74+ amountIn: sellAmount,
75+ amountOutMinimum: 1
76+ })
77+ );
78+ }
5679 }
5780}
0 commit comments