dsa-connectors/contracts/mainnet/connectors/swap/main.sol

45 lines
1.3 KiB
Solidity
Raw Normal View History

2022-06-04 19:04:58 +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 22:08:28 +00:00
import { Events } from "./events.sol";
2022-06-04 19:04:58 +00:00
2022-06-14 22:08:28 +00:00
abstract contract Swap is SwapHelpers, Events {
2022-06-04 19:04:58 +00:00
/**
* @dev Swap ETH/ERC20_Token using dex aggregators.
* @notice Swap tokens from exchanges like 1INCH, 0x etc, with calculation done off-chain.
* @param _connectors The name of the connectors like 1INCH-A, 0x etc, in order of their priority.
2022-06-15 08:37:35 +00:00
* @param _datas Encoded function call data including function selector encoded with parameters.
2022-06-04 19:04:58 +00:00
*/
2022-06-15 08:37:35 +00:00
function swap(string[] memory _connectors, bytes[] memory _datas)
2022-06-04 19:04:58 +00:00
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2022-06-14 22:08:28 +00:00
(bool success, bytes memory returnData, string memory connector) = _swap(
_connectors,
2022-06-15 08:37:35 +00:00
_datas
2022-06-14 22:08:28 +00:00
);
2022-06-04 19:04:58 +00:00
2022-06-13 08:45:21 +00:00
require(success, "swap-Aggregator-failed");
2022-06-14 22:08:28 +00:00
(string memory eventName, bytes memory eventParam) = abi.decode(
returnData,
(string, bytes)
);
_eventName = "LogSwapAggregator(string[],string,string,bytes)";
_eventParam = abi.encode(_connectors, connector, eventName, eventParam);
2022-06-04 19:04:58 +00:00
}
}
2022-06-07 00:12:03 +00:00
contract ConnectV2SwapAggregator is Swap {
string public name = "Swap-Aggregator-v1";
2022-06-04 19:04:58 +00:00
}