removing chain specific BridgeAdapters in favor of generic approach

This commit is contained in:
joshrrose
2023-01-20 14:47:28 -07:00
parent 94fe83b10f
commit 0556a59212
12 changed files with 224 additions and 864 deletions

View File

@@ -110,16 +110,10 @@
"./contracts/src/transformers/Transformer.sol",
"./contracts/src/transformers/WethTransformer.sol",
"./contracts/src/transformers/bridges/AbstractBridgeAdapter.sol",
"./contracts/src/transformers/bridges/AvalancheBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BSCBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BridgeProtocols.sol",
"./contracts/src/transformers/bridges/CeloBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BridgeAdapter.sol",
"./contracts/src/transformers/bridges/BridgeAdapterGroup1.sol",
"./contracts/src/transformers/bridges/FantomBridgeAdapter.sol",
"./contracts/src/transformers/bridges/IBridgeAdapter.sol",
"./contracts/src/transformers/bridges/OptimismBridgeAdapter.sol",
"./contracts/src/transformers/bridges/PolygonBridgeAdapter.sol",
"./contracts/src/transformers/bridges/mixins/MixinAaveV2.sol",
"./contracts/src/transformers/bridges/mixins/MixinBalancer.sol",
"./contracts/src/transformers/bridges/mixins/MixinBalancerV2Batch.sol",

View File

@@ -1,120 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV3.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinDodoV2.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinGMX.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinZeroExBridge.sol";
contract ArbitrumBridgeAdapter is
AbstractBridgeAdapter(42161, "Arbitrum"),
MixinAaveV3,
MixinBalancerV2Batch,
MixinCurve,
MixinCurveV2,
MixinDodoV2,
MixinKyberDmm,
MixinGMX,
MixinNerve,
MixinUniswapV3,
MixinUniswapV2,
MixinZeroExBridge
{
constructor(IEtherTokenV06 weth) public MixinCurve(weth) MixinAaveV3(true) {}
function _trade(
BridgeOrder memory order,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODOV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodoV2(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.KYBERDMM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeKyberDmm(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.GMX) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeGMX(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV3(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@@ -1,120 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV3.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinGMX.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinAaveV2.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinPlatypus.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
contract AvalancheBridgeAdapter is
AbstractBridgeAdapter(43114, "Avalanche"),
MixinAaveV3,
MixinCurve,
MixinCurveV2,
MixinGMX,
MixinKyberDmm,
MixinAaveV2,
MixinNerve,
MixinPlatypus,
MixinUniswapV2,
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherTokenV06 weth) public MixinCurve(weth) MixinAaveV3(false) {}
function _trade(
BridgeOrder memory order,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.KYBERDMM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeKyberDmm(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.GMX) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeGMX(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.PLATYPUS) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradePlatypus(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.WOOFI) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeWOOFi(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV3(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@@ -1,106 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinDodo.sol";
import "./mixins/MixinDodoV2.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinMooniswap.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
contract BSCBridgeAdapter is
AbstractBridgeAdapter(56, "BSC"),
MixinCurve,
MixinDodo,
MixinDodoV2,
MixinKyberDmm,
MixinMooniswap,
MixinNerve,
MixinUniswapV2,
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherTokenV06 weth) public MixinCurve(weth) MixinMooniswap(weth) {}
function _trade(
BridgeOrder memory order,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MOONISWAP) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMooniswap(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODO) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodo(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODOV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodoV2(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.KYBERDMM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeKyberDmm(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.WOOFI) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeWOOFi(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@@ -20,12 +20,17 @@
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./BridgeAdapterGroup1.sol";
import "./IBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./BridgeAdapterGroup1.sol";
import "./BridgeAdapterGroup2.sol";
contract BridgeAdapter is IBridgeAdapter {
IBridgeAdapter private immutable adapter1;
uint256 private constant ADAPTER_1_LENGTH = 33;
IBridgeAdapter private immutable adapter2;
uint256 private constant ADAPTER_1_LAST_PROTOCOL_ID = 26;
uint256 private constant ADAPTER_2_LAST_PROTOCOL_ID = 32;
constructor(IEtherTokenV06 weth, uint256 expectedChainId, string memory expectedChainName) public {
uint256 chainId;
@@ -38,6 +43,7 @@ contract BridgeAdapter is IBridgeAdapter {
}
adapter1 = new BridgeAdapterGroup1(weth);
adapter2 = new BridgeAdapterGroup2(weth);
}
function trade(
@@ -47,27 +53,37 @@ contract BridgeAdapter is IBridgeAdapter {
uint256 sellAmount
) public override returns (uint256 boughtAmount) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId < ADAPTER_1_LENGTH) {
(bool success, bytes memory resultData) = address(adapter1).delegatecall(abi.encodeWithSelector(
IBridgeAdapter.trade.selector,
order,
sellToken,
buyToken,
sellAmount
)
);
if (success) {
return abi.decode(resultData, (uint256));
}
IBridgeAdapter adapter;
if (protocolId <= ADAPTER_1_LAST_PROTOCOL_ID) {
adapter = adapter1;
} else if (protocolId <= ADAPTER_2_LAST_PROTOCOL_ID) {
adapter = adapter2;
} else {
revert("unknown protocolId");
}
revert("unknown protocolId");
(bool success, bytes memory resultData) = address(adapter).delegatecall(abi.encodeWithSelector(
IBridgeAdapter.trade.selector,
order,
sellToken,
buyToken,
sellAmount
)
);
if (success) {
return abi.decode(resultData, (uint256));
}
}
function isSupportedSource(bytes32 source) external override returns (bool isSupported) {
uint128 protocolId = uint128(uint256(source) >> 128);
if (protocolId < ADAPTER_1_LENGTH) {
if (protocolId <= ADAPTER_1_LAST_PROTOCOL_ID) {
return adapter1.isSupportedSource(source);
} else if (protocolId <= ADAPTER_2_LAST_PROTOCOL_ID) {
return adapter2.isSupportedSource(source);
} else {
revert("unknown protocolId");
}
revert("unknown protocolId");
}
}

View File

@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,65 +22,66 @@ pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV2.sol";
import "./mixins/MixinBalancer.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinBancor.sol";
import "./mixins/MixinBancorV3.sol";
import "./mixins/MixinCompound.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinCryptoCom.sol";
import "./mixins/MixinDodo.sol";
import "./mixins/MixinDodoV2.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinLido.sol";
import "./mixins/MixinMakerPSM.sol";
import "./mixins/MixinMStable.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinShell.sol";
import "./mixins/MixinSynthetix.sol";
import "./mixins/MixinUniswap.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinZeroExBridge.sol";
contract BridgeAdapterGroup1 is
import "./mixins/MixinZeroExBridge.sol"; //0
import "./mixins/MixinCurve.sol"; //1
import "./mixins/MixinUniswapV2.sol"; //2
import "./mixins/MixinUniswap.sol"; //3
import "./mixins/MixinBalancer.sol"; //4
import "./mixins/MixinMooniswap.sol"; //6
import "./mixins/MixinMStable.sol"; //7
import "./mixins/MixinShell.sol"; //9
import "./mixins/MixinDodo.sol"; //10
import "./mixins/MixinDodoV2.sol"; //11
import "./mixins/MixinCryptoCom.sol"; //12
import "./mixins/MixinBancor.sol"; //13
import "./mixins/MixinNerve.sol"; //15
import "./mixins/MixinMakerPSM.sol"; //16
import "./mixins/MixinUniswapV3.sol"; //18
import "./mixins/MixinKyberDmm.sol"; //19
import "./mixins/MixinCurveV2.sol"; //20
import "./mixins/MixinLido.sol"; //21
import "./mixins/MixinAaveV2.sol"; //23
import "./mixins/MixinCompound.sol"; //24
import "./mixins/MixinBalancerV2Batch.sol"; //25
import "./mixins/MixinGMX.sol"; //26
contract BridgeAdapterGroup1 is
AbstractBridgeAdapter,
MixinAaveV2,
MixinBalancer,
MixinBalancerV2Batch,
MixinBancor,
MixinBancorV3,
MixinCompound,
MixinZeroExBridge,
MixinCurve,
MixinCurveV2,
MixinCryptoCom,
MixinUniswapV2,
MixinUniswap,
MixinBalancer,
MixinMooniswap,
MixinMStable,
MixinShell,
MixinDodo,
MixinDodoV2,
MixinKyberDmm,
MixinLido,
MixinMakerPSM,
MixinMStable,
MixinCryptoCom,
MixinBancor,
MixinNerve,
MixinShell,
MixinSynthetix,
MixinUniswap,
MixinUniswapV2,
MixinMakerPSM,
MixinUniswapV3,
MixinZeroExBridge
MixinKyberDmm,
MixinCurveV2,
MixinLido,
MixinAaveV2,
MixinCompound,
MixinBalancerV2Batch,
MixinGMX
{
constructor(
IEtherTokenV06 weth
)
public
MixinBancor(weth)
MixinBancorV3(weth)
MixinCompound(weth)
MixinCurve(weth)
MixinLido(weth)
MixinUniswap(weth)
{}
MixinMooniswap(weth)
MixinCompound(weth)
{ }
function _trade(
BridgeOrder memory order,
@@ -90,116 +91,116 @@ contract BridgeAdapterGroup1 is
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAP) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswap(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCER) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancer(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MAKERPSM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMakerPsm(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MSTABLE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMStable(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SHELL) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeShell(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODO) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodo(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODOV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodoV2(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CRYPTOCOM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCryptoCom(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BANCOR) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBancor(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.KYBERDMM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeKyberDmm(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.LIDO) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeLido(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.COMPOUND) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCompound(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BANCORV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBancorV3(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SYNTHETIX) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeSynthetix(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVE) { //1
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) { //2
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAP) { //3
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswap(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCER) { //4
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancer(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MOONISWAP) { //6
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMooniswap(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MSTABLE) { //7
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMStable(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SHELL) { //9
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeShell(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODO) { //10
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodo(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODOV2) { //11
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodoV2(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CRYPTOCOM) { //12
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCryptoCom(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BANCOR) { //13
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBancor(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) { //15
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MAKERPSM) { //16
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMakerPsm(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) { //18
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.KYBERDMM) { //19
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeKyberDmm(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) { //20
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.LIDO) { //21
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeLido(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV2) { //23
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.COMPOUND) { //24
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCompound(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) { //25
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.GMX) { //26
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeGMX(buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);

View File

@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,25 +22,29 @@ pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
contract FantomBridgeAdapter is
AbstractBridgeAdapter(250, "Fantom"),
MixinBalancerV2Batch,
MixinCurve,
MixinCurveV2,
MixinNerve,
MixinUniswapV2,
import "./mixins/MixinPlatypus.sol"; //27
import "./mixins/MixinBancorV3.sol"; //28
import "./mixins/MixinSolidly.sol"; //29
import "./mixins/MixinSynthetix.sol"; //30
import "./mixins/MixinWOOFi.sol"; //31
import "./mixins/MixinAaveV3.sol"; //32
contract BridgeAdapterGroup2 is
AbstractBridgeAdapter,
MixinPlatypus,
MixinBancorV3,
MixinSolidly,
MixinSynthetix,
MixinWOOFi,
MixinZeroExBridge
MixinAaveV3
{
constructor(IEtherTokenV06 weth) public MixinCurve(weth) {}
constructor(
IEtherTokenV06 weth
)
public
MixinBancorV3(weth)
{ }
function _trade(
BridgeOrder memory order,
@@ -50,42 +54,37 @@ contract FantomBridgeAdapter is
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (protocolId == BridgeProtocols.PLATYPUS) { //27
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
boughtAmount = _tradePlatypus(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BANCORV3) { //28
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
boughtAmount = _tradeBancorV3(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SOLIDLY) { //29
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
boughtAmount = _tradeSolidly(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SYNTHETIX) { //30
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.WOOFI) {
boughtAmount = _tradeSynthetix(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.WOOFI) { //31
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeWOOFi(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
} else if (protocolId == BridgeProtocols.AAVEV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
}
boughtAmount = _tradeAaveV3(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}

View File

@@ -43,7 +43,7 @@ library BridgeProtocols {
uint128 internal constant COFIX = 14; // Not used: deprecated.
uint128 internal constant NERVE = 15;
uint128 internal constant MAKERPSM = 16;
uint128 internal constant BALANCERV2 = 17;
uint128 internal constant BALANCERV2 = 17; // Not used: depracated.
uint128 internal constant UNISWAPV3 = 18;
uint128 internal constant KYBERDMM = 19;
uint128 internal constant CURVEV2 = 20;

View File

@@ -1,59 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinZeroExBridge.sol";
contract CeloBridgeAdapter is AbstractBridgeAdapter(42220, "Celo"), MixinNerve, MixinUniswapV2, MixinZeroExBridge {
constructor(address _weth) public {}
function _trade(
BridgeOrder memory order,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@@ -1,101 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV3.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinSolidly.sol";
import "./mixins/MixinSynthetix.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinZeroExBridge.sol";
contract OptimismBridgeAdapter is
AbstractBridgeAdapter(10, "Optimism"),
MixinAaveV3,
MixinBalancerV2Batch,
MixinCurve,
MixinCurveV2,
MixinNerve,
MixinSynthetix,
MixinUniswapV3,
MixinSolidly,
MixinZeroExBridge
{
constructor(IEtherTokenV06 weth) public MixinCurve(weth) MixinAaveV3(true) {}
function _trade(
BridgeOrder memory order,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, 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);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SOLIDLY) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeSolidly(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SYNTHETIX) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeSynthetix(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV3(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@@ -1,148 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2022 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV3.sol";
import "./mixins/MixinAaveV2.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinDodo.sol";
import "./mixins/MixinDodoV2.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinMStable.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinSolidly.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
contract PolygonBridgeAdapter is
AbstractBridgeAdapter(137, "Polygon"),
MixinAaveV3,
MixinAaveV2,
MixinBalancerV2Batch,
MixinCurve,
MixinCurveV2,
MixinDodo,
MixinDodoV2,
MixinKyberDmm,
MixinMStable,
MixinNerve,
MixinUniswapV2,
MixinUniswapV3,
MixinSolidly,
MixinWOOFi,
MixinZeroExBridge
{
constructor(IEtherTokenV06 weth) public MixinCurve(weth) MixinAaveV3(false) {}
function _trade(
BridgeOrder memory order,
IERC20TokenV06 sellToken,
IERC20TokenV06 buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MSTABLE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMStable(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODO) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodo(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODOV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeDodoV2(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeNerve(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.KYBERDMM) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeKyberDmm(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SOLIDLY) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeSolidly(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.WOOFI) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeWOOFi(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeZeroExBridge(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.AAVEV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeAaveV3(sellToken, buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@@ -82,8 +82,12 @@ contract MixinAaveV3 {
bool private immutable _isL2;
constructor(bool isL2) public {
_isL2 = isL2;
constructor() public {
uint256 chain;
assembly {
chain := chainid()
}
_isL2 = (chain == 42161 || chain == 10); // is arbitrum or optimism
}
function _tradeAaveV3(