fixed bugs

This commit is contained in:
pradyuman-verma 2021-12-12 01:58:53 +05:30
parent 7b8659b91c
commit 494b5fd7c4
4 changed files with 0 additions and 251 deletions

View File

@ -20,11 +20,7 @@ contract Events {
uint256 getId,
uint256[] setId
);
<<<<<<< HEAD
=======
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
event LogBuy(
address indexed buyToken,
address indexed sellToken,
@ -42,8 +38,4 @@ contract Events {
uint256 getId,
uint256 setId
);
<<<<<<< HEAD
}
=======
}
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557

View File

@ -2,16 +2,12 @@ pragma solidity ^0.7.0;
interface IQuickSwapRouter {
function factory() external pure returns (address);
<<<<<<< HEAD
=======
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
<<<<<<< HEAD
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
@ -98,53 +94,4 @@ interface IQuickSwapFactory {
function createPair(address tokenA, address tokenB)
external
returns (address pair);
=======
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IQuickSwapFactory {
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function createPair(address tokenA, address tokenB) external returns (address pair);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
}

View File

@ -5,15 +5,9 @@ pragma solidity ^0.7.0;
* @dev Decentralized Exchange.
*/
<<<<<<< HEAD
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";
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
abstract contract QuickpswapResolver is Helpers, Events {
/**
@ -26,11 +20,7 @@ abstract contract QuickpswapResolver is Helpers, Events {
* @param slippage Slippage amount.
* @param getId ID to retrieve amtA.
* @param setId ID stores the amount of pools tokens received.
<<<<<<< HEAD
*/
=======
*/
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
function deposit(
address tokenA,
address tokenB,
@ -39,7 +29,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 slippage,
uint256 getId,
uint256 setId
<<<<<<< HEAD
)
external
payable
@ -66,22 +55,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
getId,
setId
);
=======
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, amtA);
(uint _amtA, uint _amtB, uint _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);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
}
/**
@ -94,11 +67,7 @@ abstract contract QuickpswapResolver is Helpers, Events {
* @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.
<<<<<<< HEAD
*/
=======
*/
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
function withdraw(
address tokenA,
address tokenB,
@ -107,7 +76,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 unitAmtB,
uint256 getId,
uint256[] calldata setIds
<<<<<<< HEAD
)
external
payable
@ -116,12 +84,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 _amt = getUint(getId, uniAmt);
(uint256 _amtA, uint256 _amtB, uint256 _uniAmt) = _removeLiquidity(
=======
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, uniAmt);
(uint _amtA, uint _amtB, uint _uniAmt) = _removeLiquidity(
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
tokenA,
tokenB,
_amt,
@ -131,7 +93,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
setUint(setIds[0], _amtA);
setUint(setIds[1], _amtB);
<<<<<<< HEAD
_eventName = "LogWithdrawLiquidity(address,address,uint256,uint256,uint256,uint256,uint256[])";
_eventParam = abi.encode(
@ -143,11 +104,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
getId,
setIds
);
=======
_eventName = "LogWithdrawLiquidity(address,address,uint256,uint256,uint256,uint256,uint256[])";
_eventParam = abi.encode(tokenA, tokenB, _amtA, _amtB, _uniAmt, getId, setIds);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
}
/**
@ -159,11 +115,7 @@ abstract contract QuickpswapResolver is Helpers, Events {
* @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.
<<<<<<< HEAD
*/
=======
*/
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
function buy(
address buyAddr,
address sellAddr,
@ -171,7 +123,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 unitAmt,
uint256 getId,
uint256 setId
<<<<<<< HEAD
)
external
payable
@ -189,34 +140,18 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 _slippageAmt = convert18ToDec(
_sellAddr.decimals(),
=======
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _buyAmt = getUint(getId, buyAmt);
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeMaticAddress(buyAddr, sellAddr);
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
uint _slippageAmt = convert18ToDec(_sellAddr.decimals(),
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt))
);
checkPair(paths);
<<<<<<< HEAD
uint256 _expectedAmt = getExpectedSellAmt(paths, _buyAmt);
=======
uint _expectedAmt = getExpectedSellAmt(paths, _buyAmt);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
require(_slippageAmt >= _expectedAmt, "Too much slippage");
bool isEth = address(_sellAddr) == wmaticAddr;
convertMaticToWmatic(isEth, _sellAddr, _expectedAmt);
approve(_sellAddr, address(router), _expectedAmt);
<<<<<<< HEAD
uint256 _sellAmt = router.swapTokensForExactTokens(
=======
uint _sellAmt = router.swapTokensForExactTokens(
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
_buyAmt,
_expectedAmt,
paths,
@ -230,7 +165,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
setUint(setId, _sellAmt);
_eventName = "LogBuy(address,address,uint256,uint256,uint256,uint256)";
<<<<<<< HEAD
_eventParam = abi.encode(
buyAddr,
sellAddr,
@ -239,9 +173,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
getId,
setId
);
=======
_eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
}
/**
@ -253,11 +184,7 @@ abstract contract QuickpswapResolver is Helpers, Events {
* @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.
<<<<<<< HEAD
*/
=======
*/
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
function sell(
address buyAddr,
address sellAddr,
@ -265,7 +192,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 unitAmt,
uint256 getId,
uint256 setId
<<<<<<< HEAD
)
external
payable
@ -289,40 +215,18 @@ abstract contract QuickpswapResolver is Helpers, Events {
uint256 _slippageAmt = convert18ToDec(
_buyAddr.decimals(),
=======
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _sellAmt = getUint(getId, sellAmt);
(TokenInterface _buyAddr, TokenInterface _sellAddr) = changeMaticAddress(buyAddr, sellAddr);
address[] memory paths = getPaths(address(_buyAddr), address(_sellAddr));
if (_sellAmt == uint(-1)) {
_sellAmt = sellAddr == maticAddr ?
address(this).balance :
_sellAddr.balanceOf(address(this));
}
uint _slippageAmt = convert18ToDec(_buyAddr.decimals(),
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt))
);
checkPair(paths);
<<<<<<< HEAD
uint256 _expectedAmt = getExpectedBuyAmt(paths, _sellAmt);
=======
uint _expectedAmt = getExpectedBuyAmt(paths, _sellAmt);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
require(_slippageAmt <= _expectedAmt, "Too much slippage");
bool isEth = address(_sellAddr) == wmaticAddr;
convertMaticToWmatic(isEth, _sellAddr, _sellAmt);
approve(_sellAddr, address(router), _sellAmt);
<<<<<<< HEAD
uint256 _buyAmt = router.swapExactTokensForTokens(
=======
uint _buyAmt = router.swapExactTokensForTokens(
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
_sellAmt,
_expectedAmt,
paths,
@ -336,7 +240,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
setUint(setId, _buyAmt);
_eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)";
<<<<<<< HEAD
_eventParam = abi.encode(
buyAddr,
sellAddr,
@ -345,9 +248,6 @@ abstract contract QuickpswapResolver is Helpers, Events {
getId,
setId
);
=======
_eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId);
>>>>>>> d9a7bfba85acceb302ac1d1dd854e9b380976557
}
}

View File

@ -1,90 +0,0 @@
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("@tenderly/hardhat-tenderly");
require("@nomiclabs/hardhat-etherscan");
require("@nomiclabs/hardhat-web3");
require("hardhat-deploy");
require("hardhat-deploy-ethers");
require("dotenv").config();
const { utils } = require("ethers");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ALCHEMY_ID = process.env.ALCHEMY_ID;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
if (!process.env.ALCHEMY_ID) {
throw new Error("ENV Variable ALCHEMY_ID not set!");
}
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
compilers: [
{
version: "0.7.6",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
{
version: "0.6.0",
},
{
version: "0.6.2",
},
{
version: "0.6.12",
},
{
version: "0.6.5",
},
],
},
networks: {
// defaultNetwork: "hardhat",
kovan: {
url: `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_ID}`,
accounts: [`0x${PRIVATE_KEY}`],
},
mainnet: {
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
accounts: [`0x${PRIVATE_KEY}`],
timeout: 150000,
gasPrice: parseInt(utils.parseUnits("30", "gwei")),
},
rinkeby: {
url: `https://eth-rinkeby.alchemyapi.io/v2/${ALCHEMY_ID}`,
accounts: [`0x${PRIVATE_KEY}`],
timeout: 150000,
},
hardhat: {
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
blockNumber: 12696000,
},
blockGasLimit: 12000000,
},
matic: {
url: "https://rpc-mainnet.maticvigil.com/",
accounts: [`0x${PRIVATE_KEY}`],
timeout: 150000,
gasPrice: parseInt(utils.parseUnits("1", "gwei")),
},
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
tenderly: {
project: process.env.TENDERLY_PROJECT,
username: process.env.TENDERLY_USERNAME,
},
mocha: {
timeout: 100 * 1000,
},
};