mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00

* raw logic * rename and output update * checks update * name & comments checks update * Updated comments for reflexer * Updated comments * colors and line numbers * commit test * commit test 2 * commit test 3 * commit test 4 * commit test 5 * commit test 6 * commit test 7 * reset branch * commit test 1 * commit test 1 * test commit 1 * test commit * test * test * test workflow Co-authored-by: Thrilok Kumar <thrilok2000@gmail.com>
57 lines
1.9 KiB
Solidity
57 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.
|
|
* @notice Sell tokens using Kyber.
|
|
* @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";
|
|
} |