feat: Add Barter support to EthereumBridgeAdapter [LIT-981] (#703)
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
[
|
||||
{
|
||||
"version": "0.40.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add Barter support on Ethereum"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.39.2",
|
||||
"changes": [
|
||||
|
@@ -55,4 +55,5 @@ library BridgeProtocols {
|
||||
uint128 internal constant WOOFI = 31;
|
||||
uint128 internal constant AAVEV3 = 32;
|
||||
uint128 internal constant KYBERELASTIC = 33;
|
||||
uint128 internal constant BARTER = 34;
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import "./mixins/MixinBalancer.sol";
|
||||
import "./mixins/MixinBalancerV2Batch.sol";
|
||||
import "./mixins/MixinBancor.sol";
|
||||
import "./mixins/MixinBancorV3.sol";
|
||||
import "./mixins/MixinBarter.sol";
|
||||
import "./mixins/MixinCompound.sol";
|
||||
import "./mixins/MixinCurve.sol";
|
||||
import "./mixins/MixinCurveV2.sol";
|
||||
@@ -48,6 +49,7 @@ contract EthereumBridgeAdapter is
|
||||
MixinBalancerV2Batch,
|
||||
MixinBancor,
|
||||
MixinBancorV3,
|
||||
MixinBarter,
|
||||
MixinCompound,
|
||||
MixinCurve,
|
||||
MixinCurveV2,
|
||||
@@ -197,6 +199,11 @@ contract EthereumBridgeAdapter is
|
||||
return (0, true);
|
||||
}
|
||||
boughtAmount = _tradeSynthetix(sellAmount, order.bridgeData);
|
||||
} else if (protocolId == BridgeProtocols.BARTER) {
|
||||
if (dryRun) {
|
||||
return (0, true);
|
||||
}
|
||||
boughtAmount = _tradeBarter(sellToken, sellAmount, order.bridgeData);
|
||||
} else if (protocolId == BridgeProtocols.UNKNOWN) {
|
||||
if (dryRun) {
|
||||
return (0, true);
|
||||
|
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
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.
|
||||
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 "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol";
|
||||
import "@0x/contracts-erc20/src/IERC20Token.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
|
||||
|
||||
contract MixinBarter {
|
||||
using LibERC20TokenV06 for IERC20Token;
|
||||
using LibRichErrorsV06 for bytes;
|
||||
|
||||
function _tradeBarter(
|
||||
IERC20Token sellToken,
|
||||
uint256 sellAmount,
|
||||
bytes memory bridgeData
|
||||
) internal returns (uint256 boughtAmount) {
|
||||
(address barterRouter, bytes memory data) = abi.decode(bridgeData, (address, bytes));
|
||||
sellToken.approveIfBelow(barterRouter, sellAmount);
|
||||
|
||||
(bool success, bytes memory resultData) = barterRouter.call(data);
|
||||
if (!success) {
|
||||
resultData.rrevert();
|
||||
}
|
||||
|
||||
return abi.decode(resultData, (uint256));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user