dsa-connectors/contracts/mainnet/connectors/kyber/main.sol
2021-04-12 16:18:42 +05:30

56 lines
1.9 KiB
Solidity

pragma solidity ^0.7.0;
import { TokenInterface } from "../../common/interfaces.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
abstract contract KyberResolver is Helpers, Events {
/**
* @dev Sell ETH/ERC20_Token.
* @param buyAddr buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAddr selling token amount.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAmt selling token amount.
* @param unitAmt unit amount of buyAmt/sellAmt with slippage.
* @param getId Get token amount at this ID from `InstaMemory` Contract.
* @param setId Set token amount at this ID in `InstaMemory` Contract.
*/
function sell(
address buyAddr,
address sellAddr,
uint sellAmt,
uint unitAmt,
uint getId,
uint setId
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _sellAmt = getUint(getId, sellAmt);
uint ethAmt;
if (sellAddr == ethAddr) {
_sellAmt = _sellAmt == uint(-1) ? address(this).balance : _sellAmt;
ethAmt = _sellAmt;
} else {
TokenInterface sellContract = TokenInterface(sellAddr);
_sellAmt = _sellAmt == uint(-1) ? sellContract.balanceOf(address(this)) : _sellAmt;
sellContract.approve(address(kyber), _sellAmt);
}
uint _buyAmt = kyber.trade{value: ethAmt}(
sellAddr,
_sellAmt,
buyAddr,
address(this),
uint(-1),
unitAmt,
referalAddr
);
setUint(setId, _buyAmt);
_eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId);
}
}
contract ConnectV2Kyber is KyberResolver {
string public name = "Kyber-v2";
}