Add UniswapV3 to Avalanche and BSC bridge adapters (#735)
* Add UniswapV3 to Avalanche and BSC * Support v2 router in MixinUniswapV3 * Update Avalanche and BSC FillQuoteTransformer addresses
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
},
|
||||
{
|
||||
"note": "Add Base Mainnet and Goerli BridgeAdapters"
|
||||
},
|
||||
{
|
||||
"note": "Add Uniswap V3 support on Avalanche and BSC"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@@ -28,6 +28,7 @@ import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinPlatypus.sol";
|
||||
import "./mixins/MixinTraderJoeV2.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinUniswapV3.sol";
|
||||
import "./mixins/MixinWOOFi.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
@@ -44,6 +45,7 @@ contract AvalancheBridgeAdapter is
|
||||
MixinPlatypus,
|
||||
MixinTraderJoeV2,
|
||||
MixinUniswapV2,
|
||||
MixinUniswapV3,
|
||||
MixinWOOFi,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
@@ -72,6 +74,11 @@ contract AvalancheBridgeAdapter is
|
||||
return (0, true);
|
||||
}
|
||||
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
|
||||
if (dryRun) {
|
||||
return (0, true);
|
||||
}
|
||||
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
|
||||
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||
if (dryRun) {
|
||||
return (0, true);
|
||||
|
@@ -25,6 +25,7 @@ import "./mixins/MixinKyberElastic.sol";
|
||||
import "./mixins/MixinMooniswap.sol";
|
||||
import "./mixins/MixinNerve.sol";
|
||||
import "./mixins/MixinUniswapV2.sol";
|
||||
import "./mixins/MixinUniswapV3.sol";
|
||||
import "./mixins/MixinWOOFi.sol";
|
||||
import "./mixins/MixinZeroExBridge.sol";
|
||||
|
||||
@@ -38,6 +39,7 @@ contract BSCBridgeAdapter is
|
||||
MixinMooniswap,
|
||||
MixinNerve,
|
||||
MixinUniswapV2,
|
||||
MixinUniswapV3,
|
||||
MixinWOOFi,
|
||||
MixinZeroExBridge
|
||||
{
|
||||
@@ -61,6 +63,11 @@ contract BSCBridgeAdapter is
|
||||
return (0, true);
|
||||
}
|
||||
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
|
||||
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
|
||||
if (dryRun) {
|
||||
return (0, true);
|
||||
}
|
||||
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
|
||||
} else if (protocolId == BridgeProtocols.MOONISWAP) {
|
||||
if (dryRun) {
|
||||
return (0, true);
|
||||
|
@@ -31,6 +31,18 @@ interface IUniswapV3Router {
|
||||
function exactInput(ExactInputParams memory params) external payable returns (uint256 amountOut);
|
||||
}
|
||||
|
||||
// https://github.com/Uniswap/swap-router-contracts/blob/main/contracts/interfaces/IV3SwapRouter.sol
|
||||
interface IUniswapV3Router2 {
|
||||
struct ExactInputParams {
|
||||
bytes path;
|
||||
address recipient;
|
||||
uint256 amountIn;
|
||||
uint256 amountOutMinimum;
|
||||
}
|
||||
|
||||
function exactInput(ExactInputParams memory params) external payable returns (uint256 amountOut);
|
||||
}
|
||||
|
||||
contract MixinUniswapV3 {
|
||||
using LibERC20TokenV06 for IERC20Token;
|
||||
|
||||
@@ -39,19 +51,30 @@ contract MixinUniswapV3 {
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
) internal returns (uint256 boughtAmount) {
|
||||
(IUniswapV3Router router, bytes memory path) = abi.decode(bridgeData, (IUniswapV3Router, bytes));
|
||||
(address router, bytes memory path, uint256 routerVersion) = abi.decode(bridgeData, (address, bytes, uint256));
|
||||
|
||||
// Grant the Uniswap router an allowance to sell the sell token.
|
||||
sellToken.approveIfBelow(address(router), sellAmount);
|
||||
sellToken.approveIfBelow(router, sellAmount);
|
||||
|
||||
boughtAmount = router.exactInput(
|
||||
IUniswapV3Router.ExactInputParams({
|
||||
path: path,
|
||||
recipient: address(this),
|
||||
deadline: block.timestamp,
|
||||
amountIn: sellAmount,
|
||||
amountOutMinimum: 1
|
||||
})
|
||||
);
|
||||
if (routerVersion != 2) {
|
||||
boughtAmount = IUniswapV3Router(router).exactInput(
|
||||
IUniswapV3Router.ExactInputParams({
|
||||
path: path,
|
||||
recipient: address(this),
|
||||
deadline: block.timestamp,
|
||||
amountIn: sellAmount,
|
||||
amountOutMinimum: 1
|
||||
})
|
||||
);
|
||||
} else {
|
||||
boughtAmount = IUniswapV3Router2(router).exactInput(
|
||||
IUniswapV3Router2.ExactInputParams({
|
||||
path: path,
|
||||
recipient: address(this),
|
||||
amountIn: sellAmount,
|
||||
amountOutMinimum: 1
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user