diff --git a/contracts/polygon/connectors/quickswap/events.sol b/contracts/polygon/connectors/quickswap/events.sol index c8fc41d6..9e01ef9d 100644 --- a/contracts/polygon/connectors/quickswap/events.sol +++ b/contracts/polygon/connectors/quickswap/events.sol @@ -1,41 +1,41 @@ pragma solidity ^0.7.0; contract Events { - event LogDepositLiquidity( - address indexed tokenA, - address indexed tokenB, - uint256 amtA, - uint256 amtB, - uint256 uniAmount, - uint256 getId, - uint256 setId - ); + event LogDepositLiquidity( + address indexed tokenA, + address indexed tokenB, + uint256 amtA, + uint256 amtB, + uint256 uniAmount, + uint256 getId, + uint256 setId + ); - event LogWithdrawLiquidity( - address indexed tokenA, - address indexed tokenB, - uint256 amountA, - uint256 amountB, - uint256 uniAmount, - uint256 getId, - uint256[] setId - ); + event LogWithdrawLiquidity( + address indexed tokenA, + address indexed tokenB, + uint256 amountA, + uint256 amountB, + uint256 uniAmount, + uint256 getId, + uint256[] setId + ); - event LogBuy( - address indexed buyToken, - address indexed sellToken, - uint256 buyAmt, - uint256 sellAmt, - uint256 getId, - uint256 setId - ); + event LogBuy( + address indexed buyToken, + address indexed sellToken, + uint256 buyAmt, + uint256 sellAmt, + uint256 getId, + uint256 setId + ); - event LogSell( - address indexed buyToken, - address indexed sellToken, - uint256 buyAmt, - uint256 sellAmt, - uint256 getId, - uint256 setId - ); + event LogSell( + address indexed buyToken, + address indexed sellToken, + uint256 buyAmt, + uint256 sellAmt, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/polygon/connectors/quickswap/helpers.sol b/contracts/polygon/connectors/quickswap/helpers.sol index 07316a2c..594b56e1 100644 --- a/contracts/polygon/connectors/quickswap/helpers.sol +++ b/contracts/polygon/connectors/quickswap/helpers.sol @@ -1,184 +1,184 @@ pragma solidity ^0.7.0; -import {TokenInterface} from "../../common/interfaces.sol"; -import {DSMath} from "../../common/math.sol"; -import {Basic} from "../../common/basic.sol"; -import {IQuickSwapRouter, IQuickSwapFactory} from "./interface.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { IQuickSwapRouter, IQuickSwapFactory } from "./interface.sol"; abstract contract Helpers is DSMath, Basic { - /** - * @dev IQuickSwapRouter - */ - IQuickSwapRouter internal constant router = - IQuickSwapRouter(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff); + /** + * @dev IQuickSwapRouter + */ + IQuickSwapRouter internal constant router = + IQuickSwapRouter(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff); - function getExpectedBuyAmt(address[] memory paths, uint256 sellAmt) - internal - view - returns (uint256 buyAmt) - { - uint256[] memory amts = router.getAmountsOut(sellAmt, paths); - buyAmt = amts[1]; - } + function getExpectedBuyAmt(address[] memory paths, uint256 sellAmt) + internal + view + returns (uint256 buyAmt) + { + uint256[] memory amts = router.getAmountsOut(sellAmt, paths); + buyAmt = amts[1]; + } - function getExpectedSellAmt(address[] memory paths, uint256 buyAmt) - internal - view - returns (uint256 sellAmt) - { - uint256[] memory amts = router.getAmountsIn(buyAmt, paths); - sellAmt = amts[0]; - } + function getExpectedSellAmt(address[] memory paths, uint256 buyAmt) + internal + view + returns (uint256 sellAmt) + { + uint256[] memory amts = router.getAmountsIn(buyAmt, paths); + sellAmt = amts[0]; + } - function checkPair(address[] memory paths) internal view { - address pair = IQuickSwapFactory(router.factory()).getPair( - paths[0], - paths[1] - ); - require(pair != address(0), "No-exchange-address"); - } + function checkPair(address[] memory paths) internal view { + address pair = IQuickSwapFactory(router.factory()).getPair( + paths[0], + paths[1] + ); + require(pair != address(0), "No-exchange-address"); + } - function getPaths(address buyAddr, address sellAddr) - internal - pure - returns (address[] memory paths) - { - paths = new address[](2); - paths[0] = address(sellAddr); - paths[1] = address(buyAddr); - } + function getPaths(address buyAddr, address sellAddr) + internal + pure + returns (address[] memory paths) + { + paths = new address[](2); + paths[0] = address(sellAddr); + paths[1] = address(buyAddr); + } - function getMinAmount( - TokenInterface token, - uint256 amt, - uint256 slippage - ) internal view returns (uint256 minAmt) { - uint256 _amt18 = convertTo18(token.decimals(), amt); - minAmt = wmul(_amt18, sub(WAD, slippage)); - minAmt = convert18ToDec(token.decimals(), minAmt); - } + function getMinAmount( + TokenInterface token, + uint256 amt, + uint256 slippage + ) internal view returns (uint256 minAmt) { + uint256 _amt18 = convertTo18(token.decimals(), amt); + minAmt = wmul(_amt18, sub(WAD, slippage)); + minAmt = convert18ToDec(token.decimals(), minAmt); + } - function _addLiquidity( - address tokenA, - address tokenB, - uint256 _amt, - uint256 unitAmt, - uint256 slippage - ) - internal - returns ( - uint256 _amtA, - uint256 _amtB, - uint256 _liquidity - ) - { - (TokenInterface _tokenA, TokenInterface _tokenB) = changeMaticAddress( - tokenA, - tokenB - ); + function _addLiquidity( + address tokenA, + address tokenB, + uint256 _amt, + uint256 unitAmt, + uint256 slippage + ) + internal + returns ( + uint256 _amtA, + uint256 _amtB, + uint256 _liquidity + ) + { + (TokenInterface _tokenA, TokenInterface _tokenB) = changeMaticAddress( + tokenA, + tokenB + ); - _amtA = _amt == uint256(-1) - ? getTokenBal(TokenInterface(tokenA)) - : _amt; - _amtB = convert18ToDec( - _tokenB.decimals(), - wmul(unitAmt, convertTo18(_tokenA.decimals(), _amtA)) - ); + _amtA = _amt == uint256(-1) + ? getTokenBal(TokenInterface(tokenA)) + : _amt; + _amtB = convert18ToDec( + _tokenB.decimals(), + wmul(unitAmt, convertTo18(_tokenA.decimals(), _amtA)) + ); - bool isMatic = address(_tokenA) == wmaticAddr; - convertMaticToWmatic(isMatic, _tokenA, _amtA); + bool isMatic = address(_tokenA) == wmaticAddr; + convertMaticToWmatic(isMatic, _tokenA, _amtA); - isMatic = address(_tokenB) == wmaticAddr; - convertMaticToWmatic(isMatic, _tokenB, _amtB); + isMatic = address(_tokenB) == wmaticAddr; + convertMaticToWmatic(isMatic, _tokenB, _amtB); - approve(_tokenA, address(router), _amtA); - approve(_tokenB, address(router), _amtB); + approve(_tokenA, address(router), _amtA); + approve(_tokenB, address(router), _amtB); - uint256 minAmtA = getMinAmount(_tokenA, _amtA, slippage); - uint256 minAmtB = getMinAmount(_tokenB, _amtB, slippage); - (_amtA, _amtB, _liquidity) = router.addLiquidity( - address(_tokenA), - address(_tokenB), - _amtA, - _amtB, - minAmtA, - minAmtA, - address(this), - block.timestamp + 1 - ); - } + uint256 minAmtA = getMinAmount(_tokenA, _amtA, slippage); + uint256 minAmtB = getMinAmount(_tokenB, _amtB, slippage); + (_amtA, _amtB, _liquidity) = router.addLiquidity( + address(_tokenA), + address(_tokenB), + _amtA, + _amtB, + minAmtA, + minAmtB, + address(this), + block.timestamp + 1 + ); + } - function _removeLiquidity( - address tokenA, - address tokenB, - uint256 _amt, - uint256 unitAmtA, - uint256 unitAmtB - ) - internal - returns ( - uint256 _amtA, - uint256 _amtB, - uint256 _uniAmt - ) - { - TokenInterface _tokenA; - TokenInterface _tokenB; - (_tokenA, _tokenB, _uniAmt) = _getRemoveLiquidityData( - tokenA, - tokenB, - _amt - ); - { - uint256 minAmtA = convert18ToDec( - _tokenA.decimals(), - wmul(unitAmtA, _uniAmt) - ); - uint256 minAmtB = convert18ToDec( - _tokenB.decimals(), - wmul(unitAmtB, _uniAmt) - ); - (_amtA, _amtB) = router.removeLiquidity( - address(_tokenA), - address(_tokenB), - _uniAmt, - minAmtA, - minAmtB, - address(this), - block.timestamp + 1 - ); - } + function _removeLiquidity( + address tokenA, + address tokenB, + uint256 _amt, + uint256 unitAmtA, + uint256 unitAmtB + ) + internal + returns ( + uint256 _amtA, + uint256 _amtB, + uint256 _uniAmt + ) + { + TokenInterface _tokenA; + TokenInterface _tokenB; + (_tokenA, _tokenB, _uniAmt) = _getRemoveLiquidityData( + tokenA, + tokenB, + _amt + ); + { + uint256 minAmtA = convert18ToDec( + _tokenA.decimals(), + wmul(unitAmtA, _uniAmt) + ); + uint256 minAmtB = convert18ToDec( + _tokenB.decimals(), + wmul(unitAmtB, _uniAmt) + ); + (_amtA, _amtB) = router.removeLiquidity( + address(_tokenA), + address(_tokenB), + _uniAmt, + minAmtA, + minAmtB, + address(this), + block.timestamp + 1 + ); + } - bool isMatic = address(_tokenA) == wmaticAddr; - convertWmaticToMatic(isMatic, _tokenA, _amtA); + bool isMatic = address(_tokenA) == wmaticAddr; + convertWmaticToMatic(isMatic, _tokenA, _amtA); - isMatic = address(_tokenB) == wmaticAddr; - convertWmaticToMatic(isMatic, _tokenB, _amtB); - } + isMatic = address(_tokenB) == wmaticAddr; + convertWmaticToMatic(isMatic, _tokenB, _amtB); + } - function _getRemoveLiquidityData( - address tokenA, - address tokenB, - uint256 _amt - ) - internal - returns ( - TokenInterface _tokenA, - TokenInterface _tokenB, - uint256 _uniAmt - ) - { - (_tokenA, _tokenB) = changeMaticAddress(tokenA, tokenB); - address exchangeAddr = IQuickSwapFactory(router.factory()).getPair( - address(_tokenA), - address(_tokenB) - ); - require(exchangeAddr != address(0), "pair-not-found."); + function _getRemoveLiquidityData( + address tokenA, + address tokenB, + uint256 _amt + ) + internal + returns ( + TokenInterface _tokenA, + TokenInterface _tokenB, + uint256 _uniAmt + ) + { + (_tokenA, _tokenB) = changeMaticAddress(tokenA, tokenB); + address exchangeAddr = IQuickSwapFactory(router.factory()).getPair( + address(_tokenA), + address(_tokenB) + ); + require(exchangeAddr != address(0), "pair-not-found."); - TokenInterface uniToken = TokenInterface(exchangeAddr); - _uniAmt = _amt == uint256(-1) - ? uniToken.balanceOf(address(this)) - : _amt; - approve(uniToken, address(router), _uniAmt); - } + TokenInterface uniToken = TokenInterface(exchangeAddr); + _uniAmt = _amt == uint256(-1) + ? uniToken.balanceOf(address(this)) + : _amt; + approve(uniToken, address(router), _uniAmt); + } } diff --git a/contracts/polygon/connectors/quickswap/interface.sol b/contracts/polygon/connectors/quickswap/interface.sol index 438d89c3..bd210215 100644 --- a/contracts/polygon/connectors/quickswap/interface.sol +++ b/contracts/polygon/connectors/quickswap/interface.sol @@ -1,97 +1,97 @@ pragma solidity ^0.7.0; interface IQuickSwapRouter { - function factory() external pure returns (address); + function factory() external pure returns (address); - function WETH() external pure returns (address); + function WETH() external pure returns (address); - function addLiquidity( - address tokenA, - address tokenB, - uint256 amountADesired, - uint256 amountBDesired, - uint256 amountAMin, - uint256 amountBMin, - address to, - uint256 deadline - ) - external - returns ( - uint256 amountA, - uint256 amountB, - uint256 liquidity - ); + function addLiquidity( + address tokenA, + address tokenB, + uint256 amountADesired, + uint256 amountBDesired, + uint256 amountAMin, + uint256 amountBMin, + address to, + uint256 deadline + ) + external + returns ( + uint256 amountA, + uint256 amountB, + uint256 liquidity + ); - function removeLiquidity( - address tokenA, - address tokenB, - uint256 liquidity, - uint256 amountAMin, - uint256 amountBMin, - address to, - uint256 deadline - ) external returns (uint256 amountA, uint256 amountB); + function removeLiquidity( + address tokenA, + address tokenB, + uint256 liquidity, + uint256 amountAMin, + uint256 amountBMin, + address to, + uint256 deadline + ) external returns (uint256 amountA, uint256 amountB); - function swapExactTokensForTokens( - uint256 amountIn, - uint256 amountOutMin, - address[] calldata path, - address to, - uint256 deadline - ) external returns (uint256[] memory amounts); + function swapExactTokensForTokens( + uint256 amountIn, + uint256 amountOutMin, + address[] calldata path, + address to, + uint256 deadline + ) external returns (uint256[] memory amounts); - function swapTokensForExactTokens( - uint256 amountOut, - uint256 amountInMax, - address[] calldata path, - address to, - uint256 deadline - ) external returns (uint256[] memory amounts); + function swapTokensForExactTokens( + uint256 amountOut, + uint256 amountInMax, + address[] calldata path, + address to, + uint256 deadline + ) external returns (uint256[] memory amounts); - function quote( - uint256 amountA, - uint256 reserveA, - uint256 reserveB - ) external pure returns (uint256 amountB); + function quote( + uint256 amountA, + uint256 reserveA, + uint256 reserveB + ) external pure returns (uint256 amountB); - function getAmountOut( - uint256 amountIn, - uint256 reserveIn, - uint256 reserveOut - ) external pure returns (uint256 amountOut); + function getAmountOut( + uint256 amountIn, + uint256 reserveIn, + uint256 reserveOut + ) external pure returns (uint256 amountOut); - function getAmountIn( - uint256 amountOut, - uint256 reserveIn, - uint256 reserveOut - ) external pure returns (uint256 amountIn); + function getAmountIn( + uint256 amountOut, + uint256 reserveIn, + uint256 reserveOut + ) external pure returns (uint256 amountIn); - function getAmountsOut(uint256 amountIn, address[] calldata path) - external - view - returns (uint256[] memory amounts); + function getAmountsOut(uint256 amountIn, address[] calldata path) + external + view + returns (uint256[] memory amounts); - function getAmountsIn(uint256 amountOut, address[] calldata path) - external - view - returns (uint256[] memory amounts); + function getAmountsIn(uint256 amountOut, address[] calldata path) + external + view + returns (uint256[] memory amounts); } interface IQuickSwapFactory { - function getPair(address tokenA, address tokenB) - external - view - returns (address pair); + function getPair(address tokenA, address tokenB) + external + view + returns (address pair); - function allPairs(uint256) external view returns (address pair); + function allPairs(uint256) external view returns (address pair); - function allPairsLength() external view returns (uint256); + function allPairsLength() external view returns (uint256); - function feeTo() external view returns (address); + function feeTo() external view returns (address); - function feeToSetter() external view returns (address); + function feeToSetter() external view returns (address); - function createPair(address tokenA, address tokenB) - external - returns (address pair); + function createPair(address tokenA, address tokenB) + external + returns (address pair); } diff --git a/contracts/polygon/connectors/quickswap/main.sol b/contracts/polygon/connectors/quickswap/main.sol index 2cc07049..6973948b 100644 --- a/contracts/polygon/connectors/quickswap/main.sol +++ b/contracts/polygon/connectors/quickswap/main.sol @@ -5,252 +5,252 @@ pragma solidity ^0.7.0; * @dev Decentralized Exchange. */ -import {TokenInterface} from "../../common/interfaces.sol"; -import {Helpers} from "./helpers.sol"; -import {Events} from "./events.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; abstract contract QuickpswapResolver is Helpers, Events { - /** - * @dev Deposit Liquidity. - * @notice Deposit Liquidity to a QuickSwap pool. - * @param tokenA The address of token A.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param tokenB The address of token B.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param amtA The amount of A tokens to deposit. - * @param unitAmt The unit amount of of amtB/amtA with slippage. - * @param slippage Slippage amount. - * @param getId ID to retrieve amtA. - * @param setId ID stores the amount of pools tokens received. - */ - function deposit( - address tokenA, - address tokenB, - uint256 amtA, - uint256 unitAmt, - uint256 slippage, - uint256 getId, - uint256 setId - ) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - uint256 _amt = getUint(getId, amtA); + /** + * @dev Deposit Liquidity. + * @notice Deposit Liquidity to a QuickSwap pool. + * @param tokenA The address of token A.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param tokenB The address of token B.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param amtA The amount of A tokens to deposit. + * @param unitAmt The unit amount of of amtB/amtA with slippage. + * @param slippage Slippage amount. + * @param getId ID to retrieve amtA. + * @param setId ID stores the amount of pools tokens received. + */ + function deposit( + address tokenA, + address tokenB, + uint256 amtA, + uint256 unitAmt, + uint256 slippage, + uint256 getId, + uint256 setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, amtA); - (uint256 _amtA, uint256 _amtB, uint256 _uniAmt) = _addLiquidity( - tokenA, - tokenB, - _amt, - unitAmt, - slippage - ); - setUint(setId, _uniAmt); + (uint256 _amtA, uint256 _amtB, uint256 _uniAmt) = _addLiquidity( + tokenA, + tokenB, + _amt, + unitAmt, + slippage + ); + setUint(setId, _uniAmt); - _eventName = "LogDepositLiquidity(address,address,uint256,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode( - tokenA, - tokenB, - _amtA, - _amtB, - _uniAmt, - getId, - setId - ); - } + _eventName = "LogDepositLiquidity(address,address,uint256,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + tokenA, + tokenB, + _amtA, + _amtB, + _uniAmt, + getId, + setId + ); + } - /** - * @dev Withdraw Liquidity. - * @notice Withdraw Liquidity from a QuickSwap pool. - * @param tokenA The address of token A.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param tokenB The address of token B.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) - * @param uniAmt The amount of pool tokens to withdraw. - * @param unitAmtA The unit amount of amtA/uniAmt with slippage. - * @param unitAmtB The unit amount of amtB/uniAmt with slippage. - * @param getId ID to retrieve uniAmt. - * @param setIds Array of IDs to store the amount tokens received. - */ - function withdraw( - address tokenA, - address tokenB, - uint256 uniAmt, - uint256 unitAmtA, - uint256 unitAmtB, - uint256 getId, - uint256[] calldata setIds - ) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - uint256 _amt = getUint(getId, uniAmt); + /** + * @dev Withdraw Liquidity. + * @notice Withdraw Liquidity from a QuickSwap pool. + * @param tokenA The address of token A.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param tokenB The address of token B.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param uniAmt The amount of pool tokens to withdraw. + * @param unitAmtA The unit amount of amtA/uniAmt with slippage. + * @param unitAmtB The unit amount of amtB/uniAmt with slippage. + * @param getId ID to retrieve uniAmt. + * @param setIds Array of IDs to store the amount tokens received. + */ + function withdraw( + address tokenA, + address tokenB, + uint256 uniAmt, + uint256 unitAmtA, + uint256 unitAmtB, + uint256 getId, + uint256[] calldata setIds + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, uniAmt); - (uint256 _amtA, uint256 _amtB, uint256 _uniAmt) = _removeLiquidity( - tokenA, - tokenB, - _amt, - unitAmtA, - unitAmtB - ); + (uint256 _amtA, uint256 _amtB, uint256 _uniAmt) = _removeLiquidity( + tokenA, + tokenB, + _amt, + unitAmtA, + unitAmtB + ); - setUint(setIds[0], _amtA); - setUint(setIds[1], _amtB); + setUint(setIds[0], _amtA); + setUint(setIds[1], _amtB); - _eventName = "LogWithdrawLiquidity(address,address,uint256,uint256,uint256,uint256,uint256[])"; - _eventParam = abi.encode( - tokenA, - tokenB, - _amtA, - _amtB, - _uniAmt, - getId, - setIds - ); - } + _eventName = "LogWithdrawLiquidity(address,address,uint256,uint256,uint256,uint256,uint256[])"; + _eventParam = abi.encode( + tokenA, + tokenB, + _amtA, + _amtB, + _uniAmt, + getId, + setIds + ); + } - /** - * @dev Buy ETH/ERC20_Token. - * @notice Buy a token using a QuickSwap - * @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 buyAmt The amount of tokens to buy. - * @param unitAmt The unit amount of sellAmt/buyAmt with slippage. - * @param getId ID to retrieve buyAmt. - * @param setId ID to store the amount of tokens sold. - */ - function buy( - address buyAddr, - address sellAddr, - uint256 buyAmt, - uint256 unitAmt, - uint256 getId, - uint256 setId - ) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - uint256 _buyAmt = getUint(getId, buyAmt); - ( - TokenInterface _buyAddr, - TokenInterface _sellAddr - ) = changeMaticAddress(buyAddr, sellAddr); - address[] memory paths = getPaths( - address(_buyAddr), - address(_sellAddr) - ); + /** + * @dev Buy ETH/ERC20_Token. + * @notice Buy a token using a QuickSwap + * @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 buyAmt The amount of tokens to buy. + * @param unitAmt The unit amount of sellAmt/buyAmt with slippage. + * @param getId ID to retrieve buyAmt. + * @param setId ID to store the amount of tokens sold. + */ + function buy( + address buyAddr, + address sellAddr, + uint256 buyAmt, + uint256 unitAmt, + uint256 getId, + uint256 setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _buyAmt = getUint(getId, buyAmt); + ( + TokenInterface _buyAddr, + TokenInterface _sellAddr + ) = changeMaticAddress(buyAddr, sellAddr); + address[] memory paths = getPaths( + address(_buyAddr), + address(_sellAddr) + ); - uint256 _slippageAmt = convert18ToDec( - _sellAddr.decimals(), - wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt)) - ); + uint256 _slippageAmt = convert18ToDec( + _sellAddr.decimals(), + wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt)) + ); - checkPair(paths); - uint256 _expectedAmt = getExpectedSellAmt(paths, _buyAmt); - require(_slippageAmt >= _expectedAmt, "Too much slippage"); + checkPair(paths); + uint256 _expectedAmt = getExpectedSellAmt(paths, _buyAmt); + require(_slippageAmt >= _expectedAmt, "Too much slippage"); - bool isEth = address(_sellAddr) == wmaticAddr; - convertMaticToWmatic(isEth, _sellAddr, _expectedAmt); - approve(_sellAddr, address(router), _expectedAmt); + bool isEth = address(_sellAddr) == wmaticAddr; + convertMaticToWmatic(isEth, _sellAddr, _expectedAmt); + approve(_sellAddr, address(router), _expectedAmt); - uint256 _sellAmt = router.swapTokensForExactTokens( - _buyAmt, - _expectedAmt, - paths, - address(this), - block.timestamp + 1 - )[0]; + uint256 _sellAmt = router.swapTokensForExactTokens( + _buyAmt, + _expectedAmt, + paths, + address(this), + block.timestamp + 1 + )[0]; - isEth = address(_buyAddr) == wmaticAddr; - convertWmaticToMatic(isEth, _buyAddr, _buyAmt); + isEth = address(_buyAddr) == wmaticAddr; + convertWmaticToMatic(isEth, _buyAddr, _buyAmt); - setUint(setId, _sellAmt); + setUint(setId, _sellAmt); - _eventName = "LogBuy(address,address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode( - buyAddr, - sellAddr, - _buyAmt, - _sellAmt, - getId, - setId - ); - } + _eventName = "LogBuy(address,address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + buyAddr, + sellAddr, + _buyAmt, + _sellAmt, + getId, + setId + ); + } - /** - * @dev Sell ETH/ERC20_Token. - * @notice Sell a token using a QuickSwap - * @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 unit amount of buyAmt/sellAmt with slippage. - * @param getId ID to retrieve sellAmt. - * @param setId ID stores the amount of token brought. - */ - function sell( - address buyAddr, - address sellAddr, - uint256 sellAmt, - uint256 unitAmt, - uint256 getId, - uint256 setId - ) - external - payable - returns (string memory _eventName, bytes memory _eventParam) - { - uint256 _sellAmt = getUint(getId, sellAmt); - ( - TokenInterface _buyAddr, - TokenInterface _sellAddr - ) = changeMaticAddress(buyAddr, sellAddr); - address[] memory paths = getPaths( - address(_buyAddr), - address(_sellAddr) - ); + /** + * @dev Sell ETH/ERC20_Token. + * @notice Sell a token using a QuickSwap + * @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 unit amount of buyAmt/sellAmt with slippage. + * @param getId ID to retrieve sellAmt. + * @param setId ID stores the amount of token brought. + */ + function sell( + address buyAddr, + address sellAddr, + uint256 sellAmt, + uint256 unitAmt, + uint256 getId, + uint256 setId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _sellAmt = getUint(getId, sellAmt); + ( + TokenInterface _buyAddr, + TokenInterface _sellAddr + ) = changeMaticAddress(buyAddr, sellAddr); + address[] memory paths = getPaths( + address(_buyAddr), + address(_sellAddr) + ); - if (_sellAmt == uint256(-1)) { - _sellAmt = sellAddr == maticAddr - ? address(this).balance - : _sellAddr.balanceOf(address(this)); - } + if (_sellAmt == uint256(-1)) { + _sellAmt = sellAddr == maticAddr + ? address(this).balance + : _sellAddr.balanceOf(address(this)); + } - uint256 _slippageAmt = convert18ToDec( - _buyAddr.decimals(), - wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt)) - ); + uint256 _slippageAmt = convert18ToDec( + _buyAddr.decimals(), + wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt)) + ); - checkPair(paths); - uint256 _expectedAmt = getExpectedBuyAmt(paths, _sellAmt); - require(_slippageAmt <= _expectedAmt, "Too much slippage"); + checkPair(paths); + uint256 _expectedAmt = getExpectedBuyAmt(paths, _sellAmt); + require(_slippageAmt <= _expectedAmt, "Too much slippage"); - bool isEth = address(_sellAddr) == wmaticAddr; - convertMaticToWmatic(isEth, _sellAddr, _sellAmt); - approve(_sellAddr, address(router), _sellAmt); + bool isEth = address(_sellAddr) == wmaticAddr; + convertMaticToWmatic(isEth, _sellAddr, _sellAmt); + approve(_sellAddr, address(router), _sellAmt); - uint256 _buyAmt = router.swapExactTokensForTokens( - _sellAmt, - _expectedAmt, - paths, - address(this), - block.timestamp + 1 - )[1]; + uint256 _buyAmt = router.swapExactTokensForTokens( + _sellAmt, + _expectedAmt, + paths, + address(this), + block.timestamp + 1 + )[1]; - isEth = address(_buyAddr) == wmaticAddr; - convertWmaticToMatic(isEth, _buyAddr, _buyAmt); + isEth = address(_buyAddr) == wmaticAddr; + convertWmaticToMatic(isEth, _buyAddr, _buyAmt); - setUint(setId, _buyAmt); + setUint(setId, _buyAmt); - _eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode( - buyAddr, - sellAddr, - _buyAmt, - _sellAmt, - getId, - setId - ); - } + _eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + buyAddr, + sellAddr, + _buyAmt, + _sellAmt, + getId, + setId + ); + } } contract ConnectV2Quickswap is QuickpswapResolver { - string public constant name = "Quickpswap-v1.1"; + string public constant name = "Quickpswap-v1.1"; }