dsa-connectors/contracts/mainnet/connectors/0x/main.sol

65 lines
1.9 KiB
Solidity
Raw Permalink Normal View History

2022-03-22 15:24:40 +00:00
//SPDX-License-Identifier: MIT
2021-12-06 12:17:55 +00:00
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title 0x.
* @dev On-chain DEX Aggregator.
*/
import {TokenInterface, MemoryInterface} from "../../common/interfaces.sol";
import {Stores} from "../../common/stores.sol";
2021-12-26 13:08:47 +00:00
import {ZeroExData} from "./interface.sol";
2021-12-06 12:17:55 +00:00
import {Helpers} from "./helpers.sol";
import {Events} from "./events.sol";
2021-12-06 16:44:25 +00:00
abstract contract ZeroEx is Helpers {
2021-12-06 12:17:55 +00:00
/**
2021-12-06 17:51:03 +00:00
* @notice Swap tokens on 0x
2021-12-06 12:17:55 +00:00
* @dev Sell ETH/ERC20_Token using 0x.
* @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAmt The amount of the token to sell.
* @param unitAmt The amount of buyAmt/sellAmt with slippage.
* @param callData Data from 0x API.
* @param setId ID stores the amount of token brought.
*/
function swap(
address buyAddr,
address sellAddr,
uint256 sellAmt,
uint256 unitAmt,
bytes calldata callData,
uint256 setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
ZeroExData memory zeroExData = ZeroExData({
buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr),
unitAmt: unitAmt,
callData: callData,
_sellAmt: sellAmt,
_buyAmt: 0
});
zeroExData = _swap(zeroExData, setId);
_eventName = "LogSwap(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
buyAddr,
sellAddr,
zeroExData._buyAmt,
zeroExData._sellAmt,
0,
setId
);
}
}
contract ConnectV2ZeroEx is ZeroEx {
2021-12-06 16:44:25 +00:00
string public name = "0x-V4";
2021-12-06 12:17:55 +00:00
}