2022-06-04 03:43:19 +00:00
|
|
|
//SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @title Swap.
|
|
|
|
* @dev Swap integration for DEX Aggregators.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// import files
|
|
|
|
import { SwapHelpers } from "./helpers.sol";
|
|
|
|
|
2022-06-14 03:59:01 +00:00
|
|
|
abstract contract Swap is SwapHelpers {
|
2022-06-04 03:43:19 +00:00
|
|
|
/**
|
|
|
|
* @dev Swap ETH/ERC20_Token using dex aggregators.
|
2022-06-04 04:39:03 +00:00
|
|
|
* @notice Swap tokens from exchanges like 1INCH, 0x etc, with calculation done off-chain.
|
2022-06-04 03:43:19 +00:00
|
|
|
* @param _connectors The name of the connectors like 1INCH-A, 0x etc, in order of their priority.
|
2022-06-14 07:42:10 +00:00
|
|
|
* @param _data Encoded function call data including function selector encoded with parameters.
|
2022-06-04 03:43:19 +00:00
|
|
|
*/
|
2022-06-14 07:42:10 +00:00
|
|
|
function swap(string[] memory _connectors, bytes[] memory _data)
|
2022-06-04 03:43:19 +00:00
|
|
|
external
|
|
|
|
payable
|
|
|
|
returns (string memory _eventName, bytes memory _eventParam)
|
|
|
|
{
|
2022-06-14 07:42:10 +00:00
|
|
|
(bool success, bytes memory returnData) = _swap(_connectors, _data);
|
2022-06-04 03:43:19 +00:00
|
|
|
|
2022-06-13 08:45:21 +00:00
|
|
|
require(success, "swap-Aggregator-failed");
|
2022-06-14 03:12:15 +00:00
|
|
|
(_eventName, _eventParam) = abi.decode(returnData, (string, bytes));
|
2022-06-04 03:43:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 00:12:03 +00:00
|
|
|
contract ConnectV2SwapAggregatorPolygon is Swap {
|
|
|
|
string public name = "Swap-Aggregator-v1";
|
2022-06-04 03:43:19 +00:00
|
|
|
}
|