mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Done refactoring
This commit is contained in:
parent
dd48873a1a
commit
6d278d1648
|
@ -95,7 +95,7 @@ contract OneHelpers is Stores, DSMath {
|
|||
}
|
||||
|
||||
function getReferralAddr() internal pure returns (address) {
|
||||
return 0xa7615CD307F323172331865181DC8b80a2834324;
|
||||
return 0xa7615CD307F323172331865181DC8b80a2834324; // TODO - change address
|
||||
}
|
||||
|
||||
function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
|
||||
|
@ -152,7 +152,7 @@ contract OneHelpers is Stores, DSMath {
|
|||
uint feeCollectorAmt = wmul(feeAmount, 3 * 10 ** 17);
|
||||
uint restAmt = sub(feeAmount, feeCollectorAmt);
|
||||
_transfer(payable(feeCollector), IERC20(token), feeCollectorAmt);
|
||||
_transfer(payable(getReferralAddr()), IERC20(token), restAmt); // TODO - change address
|
||||
_transfer(payable(getReferralAddr()), IERC20(token), restAmt);
|
||||
} else {
|
||||
leftAmt = amount;
|
||||
}
|
||||
|
@ -171,16 +171,23 @@ contract Resolver is OneHelpers {
|
|||
isOk = sig == getOneInchSig();
|
||||
}
|
||||
|
||||
function oneProtoSwap(
|
||||
OneProtoInterface oneSplitContract,
|
||||
TokenInterface _sellAddr,
|
||||
TokenInterface _buyAddr,
|
||||
uint _sellAmt,
|
||||
uint unitAmt,
|
||||
uint[] memory distribution,
|
||||
uint disableDexes
|
||||
) internal returns (uint buyAmt){
|
||||
uint _slippageAmt = getSlippageAmt(_buyAddr, _sellAddr, _sellAmt, unitAmt);
|
||||
struct OneProtoData {
|
||||
TokenInterface sellToken;
|
||||
TokenInterface buyToken;
|
||||
uint _sellAmt;
|
||||
uint _buyAmt;
|
||||
uint unitAmt;
|
||||
address feeCollector;
|
||||
uint256 feeAmount;
|
||||
uint[] distribution;
|
||||
uint disableDexes;
|
||||
}
|
||||
function oneProtoSwap(OneProtoInterface oneSplitContract, OneProtoData memory oneProtoData) internal returns (uint buyAmt){
|
||||
TokenInterface _sellAddr = oneProtoData.sellToken;
|
||||
TokenInterface _buyAddr = oneProtoData.buyToken;
|
||||
uint _sellAmt = oneProtoData._sellAmt;
|
||||
|
||||
uint _slippageAmt = getSlippageAmt(_buyAddr, _sellAddr, _sellAmt, oneProtoData.unitAmt);
|
||||
|
||||
uint ethAmt;
|
||||
if (address(_sellAddr) == getEthAddr()) {
|
||||
|
@ -196,8 +203,8 @@ contract Resolver is OneHelpers {
|
|||
_buyAddr,
|
||||
_sellAmt,
|
||||
_slippageAmt,
|
||||
distribution,
|
||||
disableDexes,
|
||||
oneProtoData.distribution,
|
||||
oneProtoData.disableDexes,
|
||||
getReferralAddr(),
|
||||
0
|
||||
);
|
||||
|
@ -208,17 +215,24 @@ contract Resolver is OneHelpers {
|
|||
require(_slippageAmt <= buyAmt, "Too much slippage");
|
||||
}
|
||||
|
||||
function oneProtoSwapMulti(
|
||||
address[] memory tokens,
|
||||
TokenInterface _sellAddr,
|
||||
TokenInterface _buyAddr,
|
||||
uint _sellAmt,
|
||||
uint unitAmt,
|
||||
uint[] memory distribution,
|
||||
uint[] memory disableDexes
|
||||
) internal returns (uint buyAmt){
|
||||
struct OneProtoMultiData {
|
||||
address[] tokens;
|
||||
TokenInterface sellToken;
|
||||
TokenInterface buyToken;
|
||||
uint _sellAmt;
|
||||
uint _buyAmt;
|
||||
uint unitAmt;
|
||||
address feeCollector;
|
||||
uint256 feeAmount;
|
||||
uint[] distribution;
|
||||
uint[] disableDexes;
|
||||
}
|
||||
function oneProtoSwapMulti(OneProtoMultiData memory oneProtoData) internal returns (uint buyAmt){
|
||||
OneProtoInterface oneSplitContract = OneProtoInterface(getOneProtoAddress());
|
||||
uint _slippageAmt = getSlippageAmt(_buyAddr, _sellAddr, _sellAmt, unitAmt);
|
||||
TokenInterface _sellAddr = oneProtoData.sellToken;
|
||||
TokenInterface _buyAddr = oneProtoData.buyToken;
|
||||
uint _sellAmt = oneProtoData._sellAmt;
|
||||
uint _slippageAmt = getSlippageAmt(_buyAddr, _sellAddr, _sellAmt, oneProtoData.unitAmt);
|
||||
|
||||
uint ethAmt;
|
||||
if (address(_sellAddr) == getEthAddr()) {
|
||||
|
@ -229,11 +243,11 @@ contract Resolver is OneHelpers {
|
|||
|
||||
uint initalBal = getTokenBal(_buyAddr);
|
||||
oneSplitContract.swapWithReferralMulti.value(ethAmt)(
|
||||
convertToTokenInterface(tokens),
|
||||
convertToTokenInterface(oneProtoData.tokens),
|
||||
_sellAmt,
|
||||
_slippageAmt,
|
||||
distribution,
|
||||
disableDexes,
|
||||
oneProtoData.distribution,
|
||||
oneProtoData.disableDexes,
|
||||
getReferralAddr(),
|
||||
0
|
||||
);
|
||||
|
@ -266,6 +280,7 @@ contract Resolver is OneHelpers {
|
|||
|
||||
require(_slippageAmt <= buyAmt, "Too much slippage");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract OneProtoEventResolver is Resolver {
|
||||
|
@ -278,22 +293,64 @@ contract OneProtoEventResolver is Resolver {
|
|||
uint256 setId
|
||||
);
|
||||
|
||||
function emitLogSell(
|
||||
address buyToken,
|
||||
address sellToken,
|
||||
event LogSellFee(
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
address feeCollector,
|
||||
uint256 feePercent,
|
||||
address indexed collector,
|
||||
uint256 fee,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
function emitLogSell(
|
||||
OneProtoData memory oneProtoData,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) internal {
|
||||
bytes32 _eventCode;
|
||||
bytes memory _eventParam;
|
||||
if (feeCollector == address(0)) {
|
||||
emit LogSell(buyToken, sellToken, buyAmt, sellAmt, getId, setId);
|
||||
if (oneProtoData.feeCollector == address(0)) {
|
||||
emit LogSell(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
_eventCode = keccak256("LogSell(address,address,uint256,uint256,uint256,uint256)");
|
||||
_eventParam = abi.encode(buyToken, sellToken, buyAmt, sellAmt, getId, setId);
|
||||
_eventParam = abi.encode(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
} else {
|
||||
emit LogSellFee(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
oneProtoData.feeCollector,
|
||||
oneProtoData.feeAmount,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
_eventCode = keccak256("LogSellFee(address,address,uint256,uint256,uint256,uint256)");
|
||||
_eventParam = abi.encode(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
oneProtoData.feeCollector,
|
||||
oneProtoData.feeAmount,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
}
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
@ -306,23 +363,65 @@ contract OneProtoEventResolver is Resolver {
|
|||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
function emitLogSellTwo(
|
||||
address buyToken,
|
||||
address sellToken,
|
||||
|
||||
event LogSellFeeTwo(
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
address feeCollector,
|
||||
uint256 feePercent,
|
||||
address indexed collector,
|
||||
uint256 fee,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
function emitLogSellTwo(
|
||||
OneProtoData memory oneProtoData,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) internal {
|
||||
bytes32 _eventCode;
|
||||
bytes memory _eventParam;
|
||||
if (feeCollector == address(0)) {
|
||||
emit LogSellTwo(buyToken, sellToken, buyAmt, sellAmt, getId, setId);
|
||||
if (oneProtoData.feeCollector == address(0)) {
|
||||
emit LogSellTwo(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
_eventCode = keccak256("LogSellTwo(address,address,uint256,uint256,uint256,uint256)");
|
||||
_eventParam = abi.encode(buyToken, sellToken, buyAmt, sellAmt, getId, setId);
|
||||
_eventParam = abi.encode(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
} else {
|
||||
emit LogSellFeeTwo(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
oneProtoData.feeCollector,
|
||||
oneProtoData.feeAmount,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
_eventCode = keccak256("LogSellFeeTwo(address,address,uint256,uint256,uint256,uint256)");
|
||||
_eventParam = abi.encode(
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
oneProtoData.feeCollector,
|
||||
oneProtoData.feeAmount,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
}
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
@ -336,32 +435,173 @@ contract OneProtoEventResolver is Resolver {
|
|||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
function emitLogSellMulti(
|
||||
address[] memory tokens,
|
||||
|
||||
event LogSellFeeMulti(
|
||||
address[] tokens,
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
address feeCollector,
|
||||
uint256 feePercent,
|
||||
address indexed collector,
|
||||
uint256 fee,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
function emitLogSellMulti(
|
||||
OneProtoMultiData memory oneProtoData,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) internal {
|
||||
address buyToken = tokens[tokens.length - 1];
|
||||
address sellToken = tokens[0];
|
||||
bytes32 _eventCode;
|
||||
bytes memory _eventParam;
|
||||
if (feeCollector == address(0)) {
|
||||
emit LogSellMulti(tokens, buyToken, sellToken, buyAmt, sellAmt, getId, setId);
|
||||
if (oneProtoData.feeCollector == address(0)) {
|
||||
emit LogSellMulti(
|
||||
oneProtoData.tokens,
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
_eventCode = keccak256("LogSellMulti(address[],address,address,uint256,uint256,uint256,uint256)");
|
||||
_eventParam = abi.encode(tokens, buyToken, sellToken, buyAmt, sellAmt, getId, setId);
|
||||
_eventParam = abi.encode(
|
||||
oneProtoData.tokens,
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
} else {
|
||||
emit LogSellFeeMulti(
|
||||
oneProtoData.tokens,
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
oneProtoData.feeCollector,
|
||||
oneProtoData.feeAmount,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
_eventCode = keccak256("LogSellFeeMulti(address[],address,address,uint256,uint256,uint256,uint256)");
|
||||
_eventParam = abi.encode(
|
||||
oneProtoData.tokens,
|
||||
address(oneProtoData.buyToken),
|
||||
address(oneProtoData.sellToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData._sellAmt,
|
||||
oneProtoData.feeCollector,
|
||||
oneProtoData.feeAmount,
|
||||
getId,
|
||||
setId
|
||||
);
|
||||
}
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
}
|
||||
contract OneProtoResolver is OneProtoEventResolver {
|
||||
contract OneProtoResolverHelpers is OneProtoEventResolver {
|
||||
function _sell(
|
||||
OneProtoData memory oneProtoData,
|
||||
uint256 feePercent,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) internal {
|
||||
uint _sellAmt = getUint(getId, oneProtoData._sellAmt);
|
||||
|
||||
oneProtoData._sellAmt = _sellAmt == uint(-1) ?
|
||||
getTokenBal(oneProtoData.sellToken) :
|
||||
_sellAmt;
|
||||
|
||||
OneProtoInterface oneSplitContract = OneProtoInterface(getOneProtoAddress());
|
||||
|
||||
(, oneProtoData.distribution) = oneSplitContract.getExpectedReturn(
|
||||
oneProtoData.sellToken,
|
||||
oneProtoData.buyToken,
|
||||
oneProtoData._sellAmt,
|
||||
5,
|
||||
0
|
||||
);
|
||||
|
||||
oneProtoData._buyAmt = oneProtoSwap(
|
||||
oneSplitContract,
|
||||
oneProtoData
|
||||
);
|
||||
|
||||
(uint feeAmount, uint leftBuyAmt) = takeFee(
|
||||
address(oneProtoData.buyToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData.feeCollector,
|
||||
feePercent
|
||||
);
|
||||
setUint(setId, leftBuyAmt);
|
||||
oneProtoData.feeAmount = feeAmount;
|
||||
|
||||
emitLogSell(oneProtoData, getId, setId);
|
||||
}
|
||||
|
||||
function _sellTwo(
|
||||
OneProtoData memory oneProtoData,
|
||||
uint256 feePercent,
|
||||
uint getId,
|
||||
uint setId
|
||||
) internal {
|
||||
uint _sellAmt = getUint(getId, oneProtoData._sellAmt);
|
||||
|
||||
oneProtoData._sellAmt = _sellAmt == uint(-1) ?
|
||||
getTokenBal(oneProtoData.sellToken) :
|
||||
_sellAmt;
|
||||
|
||||
oneProtoData._buyAmt = oneProtoSwap(
|
||||
OneProtoInterface(getOneProtoAddress()),
|
||||
oneProtoData
|
||||
);
|
||||
|
||||
(uint feeAmount, uint leftBuyAmt) = takeFee(
|
||||
address(oneProtoData.buyToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData.feeCollector,
|
||||
feePercent
|
||||
);
|
||||
setUint(setId, leftBuyAmt);
|
||||
oneProtoData.feeAmount = feeAmount;
|
||||
|
||||
emitLogSellTwo(oneProtoData, getId, setId);
|
||||
}
|
||||
|
||||
function _sellMulti(
|
||||
OneProtoMultiData memory oneProtoData,
|
||||
uint256 feePercent,
|
||||
uint getId,
|
||||
uint setId
|
||||
) internal {
|
||||
uint _sellAmt = getUint(getId, oneProtoData._sellAmt);
|
||||
|
||||
oneProtoData._sellAmt = _sellAmt == uint(-1) ?
|
||||
getTokenBal(oneProtoData.sellToken) :
|
||||
_sellAmt;
|
||||
|
||||
oneProtoData._buyAmt = oneProtoSwapMulti(oneProtoData);
|
||||
uint leftBuyAmt;
|
||||
(oneProtoData.feeAmount, leftBuyAmt) = takeFee(
|
||||
address(oneProtoData.buyToken),
|
||||
oneProtoData._buyAmt,
|
||||
oneProtoData.feeCollector,
|
||||
feePercent
|
||||
);
|
||||
setUint(setId, leftBuyAmt);
|
||||
|
||||
emitLogSellMulti(oneProtoData, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract OneProtoResolver is OneProtoResolverHelpers {
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1split.
|
||||
* @dev Sell ETH/ERC20_Token using 1proto.
|
||||
* @param buyAddr buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAddr selling token amount.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAmt selling token amount.
|
||||
|
@ -377,40 +617,63 @@ contract OneProtoResolver is OneProtoEventResolver {
|
|||
uint getId,
|
||||
uint setId
|
||||
) external payable {
|
||||
uint _sellAmt = getUint(getId, sellAmt);
|
||||
OneProtoData memory oneProtoData = OneProtoData({
|
||||
buyToken: TokenInterface(buyAddr),
|
||||
sellToken: TokenInterface(sellAddr),
|
||||
unitAmt: unitAmt,
|
||||
distribution: new uint[](0),
|
||||
feeCollector: address(0),
|
||||
_sellAmt: sellAmt,
|
||||
_buyAmt: 0,
|
||||
disableDexes: 0,
|
||||
feeAmount: 0
|
||||
});
|
||||
|
||||
TokenInterface _buyAddr = TokenInterface(buyAddr);
|
||||
TokenInterface _sellAddr = TokenInterface(sellAddr);
|
||||
_sell(oneProtoData, 0, getId, setId);
|
||||
|
||||
_sellAmt = _sellAmt == uint(-1) ? getTokenBal(_sellAddr) : _sellAmt;
|
||||
|
||||
OneProtoInterface oneSplitContract = OneProtoInterface(getOneProtoAddress());
|
||||
|
||||
(, uint[] memory distribution) = oneSplitContract.getExpectedReturn(
|
||||
_sellAddr,
|
||||
_buyAddr,
|
||||
_sellAmt,
|
||||
5,
|
||||
0
|
||||
);
|
||||
|
||||
uint _buyAmt = oneProtoSwap(
|
||||
oneSplitContract,
|
||||
_sellAddr,
|
||||
_buyAddr,
|
||||
_sellAmt,
|
||||
unitAmt,
|
||||
distribution,
|
||||
0
|
||||
);
|
||||
|
||||
setUint(setId, _buyAmt);
|
||||
|
||||
emitLogSell(address(_buyAddr), address(_sellAddr), _buyAmt, _sellAmt, address(0), 0, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1split.
|
||||
* @dev Sell ETH/ERC20_Token using 1proto.
|
||||
* @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 feeCollector Fee amount to transfer.
|
||||
* @param feePercent Fee percentage on buyAmt.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function sellFee(
|
||||
address buyAddr,
|
||||
address sellAddr,
|
||||
uint sellAmt,
|
||||
uint unitAmt,
|
||||
address feeCollector,
|
||||
uint feePercent,
|
||||
uint getId,
|
||||
uint setId
|
||||
) external payable {
|
||||
require(feePercent > 0 && feePercent <= 2*10*16, "Fee more than 2%");
|
||||
require(feeCollector != address(0), "feeCollector is not vaild address");
|
||||
|
||||
OneProtoData memory oneProtoData = OneProtoData({
|
||||
buyToken: TokenInterface(buyAddr),
|
||||
sellToken: TokenInterface(sellAddr),
|
||||
unitAmt: unitAmt,
|
||||
distribution: new uint[](0),
|
||||
feeCollector: feeCollector,
|
||||
_sellAmt: sellAmt,
|
||||
_buyAmt: 0,
|
||||
disableDexes: 0,
|
||||
feeAmount: 0
|
||||
});
|
||||
|
||||
_sell(oneProtoData, feePercent, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1proto.
|
||||
* @param buyAddr buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAddr selling token amount.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAmt selling token amount.
|
||||
|
@ -430,30 +693,66 @@ contract OneProtoResolver is OneProtoEventResolver {
|
|||
uint getId,
|
||||
uint setId
|
||||
) external payable {
|
||||
uint _sellAmt = getUint(getId, sellAmt);
|
||||
OneProtoData memory oneProtoData = OneProtoData({
|
||||
buyToken: TokenInterface(buyAddr),
|
||||
sellToken: TokenInterface(sellAddr),
|
||||
unitAmt: unitAmt,
|
||||
distribution: distribution,
|
||||
disableDexes: disableDexes,
|
||||
_sellAmt: sellAmt,
|
||||
feeCollector: address(0),
|
||||
_buyAmt: 0,
|
||||
feeAmount: 0
|
||||
});
|
||||
|
||||
TokenInterface _buyAddr = TokenInterface(buyAddr);
|
||||
TokenInterface _sellAddr = TokenInterface(sellAddr);
|
||||
_sellTwo(oneProtoData, 0, getId, setId);
|
||||
}
|
||||
|
||||
_sellAmt = _sellAmt == uint(-1) ? getTokenBal(_sellAddr) : _sellAmt;
|
||||
|
||||
uint _buyAmt = oneProtoSwap(
|
||||
OneProtoInterface(getOneProtoAddress()),
|
||||
_sellAddr,
|
||||
_buyAddr,
|
||||
_sellAmt,
|
||||
unitAmt,
|
||||
distribution,
|
||||
disableDexes
|
||||
);
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1proto.
|
||||
* @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 distribution distribution of swap across different dex.
|
||||
* @param disableDexes disable a dex. (To disable none: 0)
|
||||
* @param feeCollector Fee amount to transfer.
|
||||
* @param feePercent Fee percentage on buyAmt.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function sellFeeTwo(
|
||||
address buyAddr,
|
||||
address sellAddr,
|
||||
uint sellAmt,
|
||||
uint unitAmt,
|
||||
uint[] calldata distribution,
|
||||
uint disableDexes,
|
||||
address feeCollector,
|
||||
uint feePercent,
|
||||
uint getId,
|
||||
uint setId
|
||||
) external payable {
|
||||
require(feePercent > 0 && feePercent <= 2*10*16, "Fee more than 2%");
|
||||
require(feeCollector != address(0), "feeCollector is not vaild address");
|
||||
OneProtoData memory oneProtoData = OneProtoData({
|
||||
buyToken: TokenInterface(buyAddr),
|
||||
sellToken: TokenInterface(sellAddr),
|
||||
unitAmt: unitAmt,
|
||||
distribution: distribution,
|
||||
disableDexes: disableDexes,
|
||||
feeCollector: feeCollector,
|
||||
_sellAmt: sellAmt,
|
||||
_buyAmt: 0,
|
||||
feeAmount: 0
|
||||
});
|
||||
|
||||
setUint(setId, _buyAmt);
|
||||
|
||||
emitLogSellTwo(address(_buyAddr), address(_sellAddr), _buyAmt, _sellAmt, address(0), 0, getId, setId);
|
||||
_sellTwo(oneProtoData, feePercent, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1split using muliple token.
|
||||
* @dev Sell ETH/ERC20_Token using 1proto using muliple token.
|
||||
* @param tokens buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAmt selling token amount.
|
||||
* @param unitAmt unit amount of buyAmt/sellAmt with slippage.
|
||||
|
@ -471,29 +770,64 @@ contract OneProtoResolver is OneProtoEventResolver {
|
|||
uint getId,
|
||||
uint setId
|
||||
) external payable {
|
||||
uint _sellAmt = getUint(getId, sellAmt);
|
||||
require(tokens.length >= 2, "token tokens.lengthgth is less than 2");
|
||||
TokenInterface _sellAddr = TokenInterface(address(tokens[0]));
|
||||
TokenInterface _buyAddr = TokenInterface(address(tokens[tokens.length-1]));
|
||||
OneProtoMultiData memory oneProtoData = OneProtoMultiData({
|
||||
tokens: tokens,
|
||||
buyToken: TokenInterface(address(tokens[tokens.length - 1])),
|
||||
sellToken: TokenInterface(address(tokens[0])),
|
||||
unitAmt: unitAmt,
|
||||
distribution: distribution,
|
||||
disableDexes: disableDexes,
|
||||
_sellAmt: sellAmt,
|
||||
feeCollector: address(0),
|
||||
_buyAmt: 0,
|
||||
feeAmount: 0
|
||||
});
|
||||
|
||||
_sellAmt = _sellAmt == uint(-1) ? getTokenBal(_sellAddr) : _sellAmt;
|
||||
_sellMulti(oneProtoData, 0, getId, setId);
|
||||
}
|
||||
|
||||
uint _buyAmt = oneProtoSwapMulti(
|
||||
tokens,
|
||||
_sellAddr,
|
||||
_buyAddr,
|
||||
_sellAmt,
|
||||
unitAmt,
|
||||
distribution,
|
||||
disableDexes
|
||||
);
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1proto using muliple token.
|
||||
* @param tokens buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAmt selling token amount.
|
||||
* @param unitAmt unit amount of buyAmt/sellAmt with slippage.
|
||||
* @param distribution distribution of swap across different dex.
|
||||
* @param disableDexes disable a dex. (To disable none: 0)
|
||||
* @param feeCollector Fee amount to transfer.
|
||||
* @param feePercent Fee percentage on buyAmt.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function sellFeeMulti(
|
||||
address[] calldata tokens,
|
||||
uint sellAmt,
|
||||
uint unitAmt,
|
||||
uint[] calldata distribution,
|
||||
uint[] calldata disableDexes,
|
||||
address feeCollector,
|
||||
uint feePercent,
|
||||
uint getId,
|
||||
uint setId
|
||||
) external payable {
|
||||
require(feePercent > 0 && feePercent <= 2*10*16, "Fee more than 2%");
|
||||
require(feeCollector != address(0), "feeCollector is not vaild address");
|
||||
TokenInterface buyToken = TokenInterface(address(tokens[tokens.length-1]));
|
||||
OneProtoMultiData memory oneProtoData = OneProtoMultiData({
|
||||
tokens: tokens,
|
||||
buyToken: buyToken,
|
||||
sellToken: TokenInterface(address(tokens[0])),
|
||||
unitAmt: unitAmt,
|
||||
distribution: distribution,
|
||||
feeCollector: feeCollector,
|
||||
disableDexes: disableDexes,
|
||||
_sellAmt: sellAmt,
|
||||
_buyAmt: 0,
|
||||
feeAmount: 0
|
||||
});
|
||||
|
||||
setUint(setId, _buyAmt);
|
||||
|
||||
emitLogSellMulti(tokens, _buyAmt, _sellAmt, address(0), 0, getId, setId);
|
||||
_sellMulti(oneProtoData, feePercent, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract OneInchResolver is OneProtoResolver {
|
||||
event LogSellThree(
|
||||
address indexed buyToken,
|
||||
|
@ -542,6 +876,85 @@ contract OneInchResolver is OneProtoResolver {
|
|||
bytes memory _eventParam = abi.encode(address(_buyAddr), address(_sellAddr), buyAmt, sellAmt, 0, setId);
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
|
||||
event LogSellFeeThree(
|
||||
address indexed buyToken,
|
||||
address indexed sellToken,
|
||||
uint256 buyAmt,
|
||||
uint256 sellAmt,
|
||||
address indexed collector,
|
||||
uint256 fee,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Sell ETH/ERC20_Token using 1split.
|
||||
* @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 callData Data from 1inch API.
|
||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function sellFeeThree(
|
||||
address buyAddr,
|
||||
address sellAddr,
|
||||
uint sellAmt,
|
||||
uint unitAmt,
|
||||
bytes calldata callData,
|
||||
address feeCollector,
|
||||
uint feePercent,
|
||||
uint setId
|
||||
) external payable {
|
||||
require(feePercent > 0 && feePercent <= 2*10*16, "Fee more than 2%");
|
||||
require(feeCollector != address(0), "feeCollector is not vaild address");
|
||||
|
||||
TokenInterface _buyAddr = TokenInterface(buyAddr);
|
||||
TokenInterface _sellAddr = TokenInterface(sellAddr);
|
||||
|
||||
uint ethAmt;
|
||||
if (address(_sellAddr) == getEthAddr()) {
|
||||
ethAmt = sellAmt;
|
||||
} else {
|
||||
TokenInterface(_sellAddr).approve(getOneInchTokenTaker(), sellAmt);
|
||||
}
|
||||
|
||||
require(checkOneInchSig(callData), "Not-swap-function");
|
||||
|
||||
uint buyAmt = oneInchSwap(_buyAddr, _sellAddr, callData, sellAmt, unitAmt, ethAmt);
|
||||
|
||||
(uint feeAmount, uint leftBuyAmt) = takeFee(
|
||||
address(_buyAddr),
|
||||
buyAmt,
|
||||
feeCollector,
|
||||
feePercent
|
||||
);
|
||||
setUint(setId, leftBuyAmt);
|
||||
|
||||
emit LogSellFeeThree(
|
||||
address(_buyAddr),
|
||||
address(_sellAddr),
|
||||
buyAmt,
|
||||
sellAmt,
|
||||
feeCollector,
|
||||
feeAmount,
|
||||
0,
|
||||
setId
|
||||
);
|
||||
bytes32 _eventCode = keccak256("LogSellThree(address,address,uint256,uint256,uint256,uint256)");
|
||||
bytes memory _eventParam = abi.encode(
|
||||
address(_buyAddr),
|
||||
address(_sellAddr),
|
||||
buyAmt,
|
||||
sellAmt,
|
||||
feeCollector,
|
||||
feeAmount,
|
||||
0,
|
||||
setId
|
||||
);
|
||||
emitEvent(_eventCode, _eventParam);
|
||||
}
|
||||
}
|
||||
contract ConnectOne is OneInchResolver {
|
||||
string public name = "1Inch-1proto-v1";
|
||||
|
|
Loading…
Reference in New Issue
Block a user