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:
parent
21c8477062
commit
4835a1b1e7
@ -10,6 +10,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"note": "Add Base Mainnet and Goerli BridgeAdapters"
|
"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/MixinPlatypus.sol";
|
||||||
import "./mixins/MixinTraderJoeV2.sol";
|
import "./mixins/MixinTraderJoeV2.sol";
|
||||||
import "./mixins/MixinUniswapV2.sol";
|
import "./mixins/MixinUniswapV2.sol";
|
||||||
|
import "./mixins/MixinUniswapV3.sol";
|
||||||
import "./mixins/MixinWOOFi.sol";
|
import "./mixins/MixinWOOFi.sol";
|
||||||
import "./mixins/MixinZeroExBridge.sol";
|
import "./mixins/MixinZeroExBridge.sol";
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ contract AvalancheBridgeAdapter is
|
|||||||
MixinPlatypus,
|
MixinPlatypus,
|
||||||
MixinTraderJoeV2,
|
MixinTraderJoeV2,
|
||||||
MixinUniswapV2,
|
MixinUniswapV2,
|
||||||
|
MixinUniswapV3,
|
||||||
MixinWOOFi,
|
MixinWOOFi,
|
||||||
MixinZeroExBridge
|
MixinZeroExBridge
|
||||||
{
|
{
|
||||||
@ -72,6 +74,11 @@ contract AvalancheBridgeAdapter is
|
|||||||
return (0, true);
|
return (0, true);
|
||||||
}
|
}
|
||||||
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
|
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) {
|
} else if (protocolId == BridgeProtocols.NERVE) {
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
return (0, true);
|
return (0, true);
|
||||||
|
@ -25,6 +25,7 @@ import "./mixins/MixinKyberElastic.sol";
|
|||||||
import "./mixins/MixinMooniswap.sol";
|
import "./mixins/MixinMooniswap.sol";
|
||||||
import "./mixins/MixinNerve.sol";
|
import "./mixins/MixinNerve.sol";
|
||||||
import "./mixins/MixinUniswapV2.sol";
|
import "./mixins/MixinUniswapV2.sol";
|
||||||
|
import "./mixins/MixinUniswapV3.sol";
|
||||||
import "./mixins/MixinWOOFi.sol";
|
import "./mixins/MixinWOOFi.sol";
|
||||||
import "./mixins/MixinZeroExBridge.sol";
|
import "./mixins/MixinZeroExBridge.sol";
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ contract BSCBridgeAdapter is
|
|||||||
MixinMooniswap,
|
MixinMooniswap,
|
||||||
MixinNerve,
|
MixinNerve,
|
||||||
MixinUniswapV2,
|
MixinUniswapV2,
|
||||||
|
MixinUniswapV3,
|
||||||
MixinWOOFi,
|
MixinWOOFi,
|
||||||
MixinZeroExBridge
|
MixinZeroExBridge
|
||||||
{
|
{
|
||||||
@ -61,6 +63,11 @@ contract BSCBridgeAdapter is
|
|||||||
return (0, true);
|
return (0, true);
|
||||||
}
|
}
|
||||||
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
|
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) {
|
} else if (protocolId == BridgeProtocols.MOONISWAP) {
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
return (0, true);
|
return (0, true);
|
||||||
|
@ -31,6 +31,18 @@ interface IUniswapV3Router {
|
|||||||
function exactInput(ExactInputParams memory params) external payable returns (uint256 amountOut);
|
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 {
|
contract MixinUniswapV3 {
|
||||||
using LibERC20TokenV06 for IERC20Token;
|
using LibERC20TokenV06 for IERC20Token;
|
||||||
|
|
||||||
@ -39,19 +51,30 @@ contract MixinUniswapV3 {
|
|||||||
uint256 sellAmount,
|
uint256 sellAmount,
|
||||||
bytes memory bridgeData
|
bytes memory bridgeData
|
||||||
) internal returns (uint256 boughtAmount) {
|
) 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.
|
// Grant the Uniswap router an allowance to sell the sell token.
|
||||||
sellToken.approveIfBelow(address(router), sellAmount);
|
sellToken.approveIfBelow(router, sellAmount);
|
||||||
|
|
||||||
boughtAmount = router.exactInput(
|
if (routerVersion != 2) {
|
||||||
IUniswapV3Router.ExactInputParams({
|
boughtAmount = IUniswapV3Router(router).exactInput(
|
||||||
path: path,
|
IUniswapV3Router.ExactInputParams({
|
||||||
recipient: address(this),
|
path: path,
|
||||||
deadline: block.timestamp,
|
recipient: address(this),
|
||||||
amountIn: sellAmount,
|
deadline: block.timestamp,
|
||||||
amountOutMinimum: 1
|
amountIn: sellAmount,
|
||||||
})
|
amountOutMinimum: 1
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
boughtAmount = IUniswapV3Router2(router).exactInput(
|
||||||
|
IUniswapV3Router2.ExactInputParams({
|
||||||
|
path: path,
|
||||||
|
recipient: address(this),
|
||||||
|
amountIn: sellAmount,
|
||||||
|
amountOutMinimum: 1
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
"changes": [
|
"changes": [
|
||||||
{
|
{
|
||||||
"note": "Add Base mainnet addresses"
|
"note": "Add Base mainnet addresses"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"note": "Add UniswapV3 support in Avalanche and BSC FillQuoteTransformers"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
"wethTransformer": "0xac3d95668c092e895cd83a9cbafe9c7d9906471f",
|
"wethTransformer": "0xac3d95668c092e895cd83a9cbafe9c7d9906471f",
|
||||||
"payTakerTransformer": "0x7e788f3a3e39cdd1944ba111fafc5fb7e59b5e90",
|
"payTakerTransformer": "0x7e788f3a3e39cdd1944ba111fafc5fb7e59b5e90",
|
||||||
"affiliateFeeTransformer": "0x043300d113de0c64684ab89c56a45cd94c7ef54c",
|
"affiliateFeeTransformer": "0x043300d113de0c64684ab89c56a45cd94c7ef54c",
|
||||||
"fillQuoteTransformer": "0x43d10801db01c28093265ef9b77d532e553fa578",
|
"fillQuoteTransformer": "0xa9c57c539690d4e1439411f648ead5b121b34a23",
|
||||||
"positiveSlippageFeeTransformer": "0x6ff35e8cbaf56d8a8f6bf9963b902a4576243030"
|
"positiveSlippageFeeTransformer": "0x6ff35e8cbaf56d8a8f6bf9963b902a4576243030"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -156,7 +156,7 @@
|
|||||||
"wethTransformer": "0x9b8b52391071d71cd4ad1e61d7f273268fa34c6c",
|
"wethTransformer": "0x9b8b52391071d71cd4ad1e61d7f273268fa34c6c",
|
||||||
"payTakerTransformer": "0xb9a4c32547bc3cdc2ee2fb13cc1a0717dac9888f",
|
"payTakerTransformer": "0xb9a4c32547bc3cdc2ee2fb13cc1a0717dac9888f",
|
||||||
"affiliateFeeTransformer": "0x105679f99d668001370b4621ad8648ac570c860f",
|
"affiliateFeeTransformer": "0x105679f99d668001370b4621ad8648ac570c860f",
|
||||||
"fillQuoteTransformer": "0x886e4f97d7e06ab66dba574a7a861046dcf7ae4f",
|
"fillQuoteTransformer": "0x463fe1a80acb62ce1e4f0a4f7b83df674c2cce2c",
|
||||||
"positiveSlippageFeeTransformer": "0xadbfdc58a24b6dbc16f21541800f43dd6e282250"
|
"positiveSlippageFeeTransformer": "0xadbfdc58a24b6dbc16f21541800f43dd6e282250"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user