From c7fc18143ca479df82ff75e8873101e88613d813 Mon Sep 17 00:00:00 2001 From: pradyuman-verma <pradyumnverma27@gmail.com> Date: Sun, 12 Dec 2021 01:29:54 +0530 Subject: [PATCH] added typescript support --- .../polygon/connectors/quickswap/events.sol | 4 +- .../connectors/quickswap/interface.sol | 108 +++++--- .../polygon/connectors/quickswap/main.sol | 146 +++++++---- test/polygon/quickswap/quickswap.test.ts | 177 +++++++++++++ test/quickswap-polygon/quickswap.test.js | 169 ------------- test/sushiswap/sushiswap.test.js | 170 ------------- .../sushiswapIncentive/sushiIncentive.test.js | 237 ------------------ 7 files changed, 356 insertions(+), 655 deletions(-) create mode 100644 test/polygon/quickswap/quickswap.test.ts delete mode 100644 test/quickswap-polygon/quickswap.test.js delete mode 100644 test/sushiswap/sushiswap.test.js delete mode 100644 test/sushiswapIncentive/sushiIncentive.test.js diff --git a/contracts/polygon/connectors/quickswap/events.sol b/contracts/polygon/connectors/quickswap/events.sol index 2717b0a3..c8fc41d6 100644 --- a/contracts/polygon/connectors/quickswap/events.sol +++ b/contracts/polygon/connectors/quickswap/events.sol @@ -20,7 +20,7 @@ contract Events { uint256 getId, uint256[] setId ); - + event LogBuy( address indexed buyToken, address indexed sellToken, @@ -38,4 +38,4 @@ contract Events { uint256 getId, uint256 setId ); -} \ No newline at end of file +} diff --git a/contracts/polygon/connectors/quickswap/interface.sol b/contracts/polygon/connectors/quickswap/interface.sol index 4986dca7..438d89c3 100644 --- a/contracts/polygon/connectors/quickswap/interface.sol +++ b/contracts/polygon/connectors/quickswap/interface.sol @@ -2,56 +2,96 @@ pragma solidity ^0.7.0; interface IQuickSwapRouter { function factory() external pure returns (address); + function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, - uint amountADesired, - uint amountBDesired, - uint amountAMin, - uint amountBMin, + uint256 amountADesired, + uint256 amountBDesired, + uint256 amountAMin, + uint256 amountBMin, address to, - uint deadline - ) external returns (uint amountA, uint amountB, uint liquidity); + uint256 deadline + ) + external + returns ( + uint256 amountA, + uint256 amountB, + uint256 liquidity + ); + function removeLiquidity( address tokenA, address tokenB, - uint liquidity, - uint amountAMin, - uint amountBMin, + uint256 liquidity, + uint256 amountAMin, + uint256 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); + uint256 deadline + ) external returns (uint256 amountA, uint256 amountB); - 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); + 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 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 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 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 allPairs(uint) external view returns (address pair); - function allPairsLength() external view returns (uint); + function getPair(address tokenA, address tokenB) + external + view + returns (address pair); + + function allPairs(uint256) external view returns (address pair); + + function allPairsLength() external view returns (uint256); function feeTo() 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 b8c0a79a..2cc07049 100644 --- a/contracts/polygon/connectors/quickswap/main.sol +++ b/contracts/polygon/connectors/quickswap/main.sol @@ -5,9 +5,9 @@ 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 { /** @@ -20,7 +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. - */ + */ function deposit( address tokenA, address tokenB, @@ -29,20 +29,32 @@ abstract contract QuickpswapResolver is Helpers, Events { uint256 slippage, uint256 getId, uint256 setId - ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _amt = getUint(getId, amtA); + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, amtA); - (uint _amtA, uint _amtB, uint _uniAmt) = _addLiquidity( - tokenA, - tokenB, - _amt, - unitAmt, - slippage - ); + (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); + _eventParam = abi.encode( + tokenA, + tokenB, + _amtA, + _amtB, + _uniAmt, + getId, + setId + ); } /** @@ -55,7 +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. - */ + */ function withdraw( address tokenA, address tokenB, @@ -64,10 +76,14 @@ abstract contract QuickpswapResolver is Helpers, Events { uint256 unitAmtB, uint256 getId, uint256[] calldata setIds - ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _amt = getUint(getId, uniAmt); + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _amt = getUint(getId, uniAmt); - (uint _amtA, uint _amtB, uint _uniAmt) = _removeLiquidity( + (uint256 _amtA, uint256 _amtB, uint256 _uniAmt) = _removeLiquidity( tokenA, tokenB, _amt, @@ -77,9 +93,17 @@ abstract contract QuickpswapResolver is Helpers, Events { 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); + _eventParam = abi.encode( + tokenA, + tokenB, + _amtA, + _amtB, + _uniAmt, + getId, + setIds + ); } /** @@ -91,7 +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. - */ + */ function buy( address buyAddr, address sellAddr, @@ -99,24 +123,35 @@ abstract contract QuickpswapResolver is Helpers, Events { uint256 unitAmt, uint256 getId, uint256 setId - ) 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)); + ) + 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) + ); - uint _slippageAmt = convert18ToDec(_sellAddr.decimals(), + uint256 _slippageAmt = convert18ToDec( + _sellAddr.decimals(), wmul(unitAmt, convertTo18(_buyAddr.decimals(), _buyAmt)) ); checkPair(paths); - uint _expectedAmt = getExpectedSellAmt(paths, _buyAmt); + 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); - uint _sellAmt = router.swapTokensForExactTokens( + uint256 _sellAmt = router.swapTokensForExactTokens( _buyAmt, _expectedAmt, paths, @@ -130,7 +165,14 @@ abstract contract QuickpswapResolver is Helpers, Events { setUint(setId, _sellAmt); _eventName = "LogBuy(address,address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); + _eventParam = abi.encode( + buyAddr, + sellAddr, + _buyAmt, + _sellAmt, + getId, + setId + ); } /** @@ -142,7 +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. - */ + */ function sell( address buyAddr, address sellAddr, @@ -150,30 +192,41 @@ abstract contract QuickpswapResolver is Helpers, Events { uint256 unitAmt, uint256 getId, uint256 setId - ) 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)); + ) + 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 == uint(-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)); } - uint _slippageAmt = convert18ToDec(_buyAddr.decimals(), + uint256 _slippageAmt = convert18ToDec( + _buyAddr.decimals(), wmul(unitAmt, convertTo18(_sellAddr.decimals(), _sellAmt)) ); checkPair(paths); - uint _expectedAmt = getExpectedBuyAmt(paths, _sellAmt); + 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); - uint _buyAmt = router.swapExactTokensForTokens( + uint256 _buyAmt = router.swapExactTokensForTokens( _sellAmt, _expectedAmt, paths, @@ -187,7 +240,14 @@ abstract contract QuickpswapResolver is Helpers, Events { setUint(setId, _buyAmt); _eventName = "LogSell(address,address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); + _eventParam = abi.encode( + buyAddr, + sellAddr, + _buyAmt, + _sellAmt, + getId, + setId + ); } } diff --git a/test/polygon/quickswap/quickswap.test.ts b/test/polygon/quickswap/quickswap.test.ts new file mode 100644 index 00000000..b831dfe5 --- /dev/null +++ b/test/polygon/quickswap/quickswap.test.ts @@ -0,0 +1,177 @@ +import { expect } from "chai"; +import hre from "hardhat"; +const { waffle, ethers } = hre; +const { provider } = waffle; + +import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; +import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; +import { encodeSpells } from "../../../scripts/tests/encodeSpells"; +import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; +import { addLiquidity } from "../../../scripts/tests/addLiquidity"; + +import { addresses } from "../../../scripts/tests/polygon/addresses"; +import { abis } from "../../../scripts/constant/abis"; +import { ConnectV2Quickswap__factory, ConnectV2Quickswap } from "../../../typechain"; +import type { Signer, Contract } from "ethers"; + +const DAI_ADDR = "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063"; + +describe("Quickswap", function() { + const connectorName = "Quickpswap-v1.1"; + + let dsaWallet0: Contract; + let masterSigner: Signer; + let instaConnectorsV2: Contract; + let connector: Contract; + + const wallets = provider.getWallets(); + const [wallet0, wallet1, wallet2, wallet3] = wallets; + before(async () => { + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + // @ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + blockNumber: 13005785, + }, + }, + ], + }); + + masterSigner = await getMasterSigner(); + instaConnectorsV2 = await ethers.getContractAt( + abis.core.connectorsV2, + addresses.core.connectorsV2 + ); + connector = await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV2Quickswap__factory, + signer: masterSigner, + connectors: instaConnectorsV2, + }); + console.log("Connector address", connector.address); + }); + + it("Should have contracts deployed.", async function() { + expect(!!instaConnectorsV2.address).to.be.true; + expect(!!connector.address).to.be.true; + expect(!!(await masterSigner.getAddress())).to.be.true; + }); + + describe("DSA wallet setup", function() { + it("Should build DSA v2", async function() { + dsaWallet0 = await buildDSAv2(wallet0.address); + expect(!!dsaWallet0.address).to.be.true; + }); + + it("Deposit ETH & DAI into DSA wallet", async function() { + await wallet0.sendTransaction({ + to: dsaWallet0.address, + value: ethers.utils.parseEther("10"), + }); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + ethers.utils.parseEther("10") + ); + + await addLiquidity( + "dai", + dsaWallet0.address, + ethers.utils.parseEther("100000") + ); + }); + + it("Deposit ETH & USDT into DSA wallet", async function() { + await wallet0.sendTransaction({ + to: dsaWallet0.address, + value: ethers.utils.parseEther("10"), + }); + expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte( + ethers.utils.parseEther("10") + ); + + await addLiquidity( + "usdt", + dsaWallet0.address, + ethers.utils.parseEther("100000") + ); + }); + }); + + describe("Main", function() { + it("Should deposit successfully", async function() { + const ethAmount = ethers.utils.parseEther("100"); // 1 ETH + const daiUnitAmount = ethers.utils.parseUnits("4", 6); // 1 ETH + const usdtAmount = Number(ethers.utils.parseEther("400")) / Math.pow(10, 12); // 1 ETH + const ethAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; + + const getId = "0"; + const setId = "0"; + + const spells = [ + { + connector: connectorName, + method: "deposit", + args: [ + ethAddress, + DAI_ADDR, + ethAmount, + daiUnitAmount, + "500000000000000000", + getId, + setId, + ], + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.address); + let receipt = await tx.wait(); + }).timeout(10000000000); + + it("Should withdraw successfully", async function() { + const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH + const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + + const getId = "0"; + const setIds = ["0", "0"]; + + const spells = [ + { + connector: connectorName, + method: "withdraw", + args: [ethAddress, DAI_ADDR, ethAmount, 0, 0, getId, setIds], + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.address); + let receipt = await tx.wait(); + }); + + it("Should buy successfully", async function() { + const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH + const daiUnitAmount = ethers.utils.parseEther("4000"); // 1 ETH + const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; + + const getId = "0"; + const setId = "0"; + + const spells = [ + { + connector: connectorName, + method: "buy", + args: [ethAddress, DAI_ADDR, ethAmount, daiUnitAmount, getId, setId], + }, + ]; + + const tx = await dsaWallet0 + .connect(wallet0) + .cast(...encodeSpells(spells), wallet1.address); + let receipt = await tx.wait(); + }); + }); +}); diff --git a/test/quickswap-polygon/quickswap.test.js b/test/quickswap-polygon/quickswap.test.js deleted file mode 100644 index e9d2d53b..00000000 --- a/test/quickswap-polygon/quickswap.test.js +++ /dev/null @@ -1,169 +0,0 @@ -const { expect } = require("chai"); -const hre = require("hardhat"); -const { waffle, ethers } = hre; -const { provider } = waffle - -const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js") -const buildDSAv2 = require("../../scripts/buildDSAv2") -const encodeSpells = require("../../scripts/encodeSpells.js") -const getMasterSigner = require("../../scripts/getMasterSigner") -const addLiquidity = require("../../scripts/addLiquidity"); - -const addresses = require("../../scripts/constant/addresses"); -const abis = require("../../scripts/constant/abis"); - -const connectV2QuickswapArtifacts = require("../../artifacts/contracts/polygon/connectors/quickswap/main.sol/ConnectV2Quickswap.json"); - -const DAI_ADDR = "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063" - -describe("Quickswap", function () { - const connectorName = "Quickpswap-v1.1" - - let dsaWallet0 - let masterSigner; - let instaConnectorsV2; - let connector; - - const wallets = provider.getWallets() - const [wallet0, wallet1, wallet2, wallet3] = wallets - before(async () => { - // await hre.network.provider.request({ - // method: "hardhat_reset", - // params: [ - // { - // forking: { - // jsonRpcUrl: hre.config.networks.hardhat.forking.url, - // blockNumber: 13005785, - // }, - // }, - // ], - // }); - masterSigner = await getMasterSigner(wallet3) - instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); - connector = await deployAndEnableConnector({ - connectorName, - contractArtifact: connectV2QuickswapArtifacts, - signer: masterSigner, - connectors: instaConnectorsV2 - }) - console.log("Connector address", connector.address) - }) - - it("Should have contracts deployed.", async function () { - expect(!!instaConnectorsV2.address).to.be.true; - expect(!!connector.address).to.be.true; - expect(!!masterSigner.address).to.be.true; - }); - - describe("DSA wallet setup", function () { - it("Should build DSA v2", async function () { - dsaWallet0 = await buildDSAv2(wallet0.address) - expect(!!dsaWallet0.address).to.be.true; - }); - - it("Deposit ETH & DAI into DSA wallet", async function () { - await wallet0.sendTransaction({ - to: dsaWallet0.address, - value: ethers.utils.parseEther("10") - }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - - await addLiquidity("dai", dsaWallet0.address, ethers.utils.parseEther("100000")); - }); - - it("Deposit ETH & USDT into DSA wallet", async function () { - await wallet0.sendTransaction({ - to: dsaWallet0.address, - value: ethers.utils.parseEther("10") - }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - - await addLiquidity("usdt", dsaWallet0.address, ethers.utils.parseEther("100000")); - }); - }); - - describe("Main", function () { - it("Should deposit successfully", async function () { - const ethAmount = ethers.utils.parseEther("100") // 1 ETH - const daiUnitAmount = ethers.utils.parseUnits("4", 6) // 1 ETH - const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12) // 1 ETH - const ethAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" - - const getId = "0" - const setId = "0" - - const spells = [ - { - connector: connectorName, - method: "deposit", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - daiUnitAmount, - "500000000000000000", - getId, - setId - ], - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }).timeout(10000000000); - - it("Should withdraw successfully", async function () { - const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setIds = ["0", "0"] - - const spells = [ - { - connector: connectorName, - method: "withdraw", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - 0, - 0, - getId, - setIds - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }); - - it("Should buy successfully", async function () { - const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH - const daiUnitAmount = ethers.utils.parseEther("4000") // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setId = "0" - - const spells = [ - { - connector: connectorName, - method: "buy", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - daiUnitAmount, - getId, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }); - }); -}) diff --git a/test/sushiswap/sushiswap.test.js b/test/sushiswap/sushiswap.test.js deleted file mode 100644 index baaf3876..00000000 --- a/test/sushiswap/sushiswap.test.js +++ /dev/null @@ -1,170 +0,0 @@ -const { expect } = require("chai"); -const hre = require("hardhat"); -const { waffle, ethers } = hre; -const { provider } = waffle - -const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js") -const buildDSAv2 = require("../../scripts/buildDSAv2") -const encodeSpells = require("../../scripts/encodeSpells.js") -const getMasterSigner = require("../../scripts/getMasterSigner") -const addLiquidity = require("../../scripts/addLiquidity"); - -const addresses = require("../../scripts/constant/addresses"); -const abis = require("../../scripts/constant/abis"); - -const connectV2SushiswapArtifacts = require("../../artifacts/contracts/mainnet/connectors/sushiswap/main.sol/ConnectV2Sushiswap.json"); - -const DAI_ADDR = "0x6b175474e89094c44da98b954eedeac495271d0f" - -describe("Sushiswap", function () { - const connectorName = "Sushiswap-v1" - - let dsaWallet0 - let masterSigner; - let instaConnectorsV2; - let connector; - - const wallets = provider.getWallets() - const [wallet0, wallet1, wallet2, wallet3] = wallets - before(async () => { - await hre.network.provider.request({ - method: "hardhat_reset", - params: [ - { - forking: { - jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 13005785, - }, - }, - ], - }); - masterSigner = await getMasterSigner(wallet3) - instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); - connector = await deployAndEnableConnector({ - connectorName, - contractArtifact: connectV2SushiswapArtifacts, - signer: masterSigner, - connectors: instaConnectorsV2 - }) - console.log("Connector address", connector.address) - }) - - it("Should have contracts deployed.", async function () { - expect(!!instaConnectorsV2.address).to.be.true; - expect(!!connector.address).to.be.true; - expect(!!masterSigner.address).to.be.true; - }); - - describe("DSA wallet setup", function () { - it("Should build DSA v2", async function () { - dsaWallet0 = await buildDSAv2(wallet0.address) - expect(!!dsaWallet0.address).to.be.true; - }); - - it("Deposit ETH & DAI into DSA wallet", async function () { - await wallet0.sendTransaction({ - to: dsaWallet0.address, - value: ethers.utils.parseEther("10") - }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - - await addLiquidity("dai", dsaWallet0.address, ethers.utils.parseEther("100000")); - }); - - it("Deposit ETH & USDT into DSA wallet", async function () { - await wallet0.sendTransaction({ - to: dsaWallet0.address, - value: ethers.utils.parseEther("10") - }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - - await addLiquidity("usdt", dsaWallet0.address, ethers.utils.parseEther("100000")); - }); - }); - - describe("Main", function () { - - it("Should deposit successfully", async function () { - const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH - const daiUnitAmount = ethers.utils.parseEther("4000") // 1 ETH - const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12) // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setId = "0" - - const spells = [ - { - connector: connectorName, - method: "deposit", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - daiUnitAmount, - "500000000000000000", - getId, - setId - ], - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }).timeout(10000000000); - - it("Should withdraw successfully", async function () { - const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setIds = ["0", "0"] - - const spells = [ - { - connector: connectorName, - method: "withdraw", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - 0, - 0, - getId, - setIds - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }); - - it("Should buy successfully", async function () { - const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH - const daiUnitAmount = ethers.utils.parseEther("4000") // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setId = "0" - - const spells = [ - { - connector: connectorName, - method: "buy", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - daiUnitAmount, - getId, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }); - }); -}) \ No newline at end of file diff --git a/test/sushiswapIncentive/sushiIncentive.test.js b/test/sushiswapIncentive/sushiIncentive.test.js deleted file mode 100644 index 1b2fd01b..00000000 --- a/test/sushiswapIncentive/sushiIncentive.test.js +++ /dev/null @@ -1,237 +0,0 @@ -const { expect } = require("chai"); -const hre = require("hardhat"); -const { waffle, ethers } = hre; -const { provider } = waffle - -const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js") -const buildDSAv2 = require("../../scripts/buildDSAv2") -const encodeSpells = require("../../scripts/encodeSpells.js") -const getMasterSigner = require("../../scripts/getMasterSigner") -const addLiquidity = require("../../scripts/addLiquidity"); - -const addresses = require("../../scripts/constant/addresses"); -const abis = require("../../scripts/constant/abis"); - -const connectV2SushiswapArtifacts = require("../../artifacts/contracts/mainnet/connectors/sushiswap/main.sol/ConnectV2Sushiswap.json"); -const connectV2SushiswapIncentiveArtifacts = require("../../artifacts/contracts/mainnet/connectors/sushi-incentive/main.sol/ConnectV2SushiswapIncentive.json"); - -const DAI_ADDR = "0x6b175474e89094c44da98b954eedeac495271d0f" -const WETH_ADDR = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" - -describe("Sushiswap", function () { - const connectorName = "Sushiswap-v1" - const incentiveConnectorName = "Sushiswp-Incentive-v1" - - let dsaWallet0 - let masterSigner; - let instaConnectorsV2; - let connector, connectorIncentive; - - const wallets = provider.getWallets() - const [wallet0, wallet1, wallet2, wallet3] = wallets - before(async () => { - await hre.network.provider.request({ - method: "hardhat_reset", - params: [ - { - forking: { - jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 13005785, - }, - }, - ], - }); - masterSigner = await getMasterSigner(wallet3) - instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); - connector = await deployAndEnableConnector({ - connectorName, - contractArtifact: connectV2SushiswapArtifacts, - signer: masterSigner, - connectors: instaConnectorsV2 - }) - console.log("Connector address", connector.address) - - connectorIncentive = await deployAndEnableConnector({ - connectorName: incentiveConnectorName, - contractArtifact: connectV2SushiswapIncentiveArtifacts, - signer: masterSigner, - connectors: instaConnectorsV2 - }) - console.log("Incentive Connector address", connectorIncentive.address) - }) - - it("Should have contracts deployed.", async function () { - expect(!!instaConnectorsV2.address).to.be.true; - expect(!!connector.address).to.be.true; - expect(!!masterSigner.address).to.be.true; - }); - - describe("DSA wallet setup", function () { - it("Should build DSA v2", async function () { - dsaWallet0 = await buildDSAv2(wallet0.address) - expect(!!dsaWallet0.address).to.be.true; - }); - - it("Deposit ETH & DAI into DSA wallet", async function () { - await wallet0.sendTransaction({ - to: dsaWallet0.address, - value: ethers.utils.parseEther("10") - }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - - await addLiquidity("dai", dsaWallet0.address, ethers.utils.parseEther("100000")); - }); - - it("Deposit ETH & USDT into DSA wallet", async function () { - await wallet0.sendTransaction({ - to: dsaWallet0.address, - value: ethers.utils.parseEther("10") - }); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); - - await addLiquidity("usdt", dsaWallet0.address, ethers.utils.parseEther("100000")); - }); - }); - - describe("Main", function () { - - it("Should deposit successfully", async function () { - const ethAmount = ethers.utils.parseEther("2") // 1 ETH - const daiUnitAmount = ethers.utils.parseEther("4000") // 1 ETH - const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12) // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setId = "0" - - const spells = [ - { - connector: connectorName, - method: "deposit", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - daiUnitAmount, - "500000000000000000", - getId, - setId - ], - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - await tx.wait() - - describe("Incentive", () => { - it("Should deposit successfully", async () => { - const getId = 0 - const setId = 0 - const spells = [ - { - connector: incentiveConnectorName, - method: "deposit", - args: [ - WETH_ADDR, - DAI_ADDR, - ethers.utils.parseEther("10"), - getId, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address) - await tx.wait(); - }) - - it("Should harvest successfully", async () => { - const setId = 0 - const spells = [ - { - connector: incentiveConnectorName, - method: "harvest", - args: [ - WETH_ADDR, - DAI_ADDR, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address) - await tx.wait(); - }) - - it("Should harvest and withdraw successfully", async () => { - const getId = 0 - const setId = 0 - const spells = [ - { - connector: incentiveConnectorName, - method: "withdrawAndHarvest", - args: [ - WETH_ADDR, - DAI_ADDR, - ethers.utils.parseEther("1"), - getId, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address) - await tx.wait(); - }) - - it("Should withdraw successfully", async () => { - const getId = 0 - const setId = 0 - const spells = [ - { - connector: incentiveConnectorName, - method: "withdraw", - args: [ - WETH_ADDR, - DAI_ADDR, - ethers.utils.parseEther("1"), - getId, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address) - await tx.wait(); - }) - }) - }).timeout(10000000000); - - it("Should buy successfully", async function () { - const ethAmount = ethers.utils.parseEther("0.1") // 1 ETH - const daiUnitAmount = ethers.utils.parseEther("4000") // 1 ETH - const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" - - const getId = "0" - const setId = "0" - - const spells = [ - { - connector: connectorName, - method: "buy", - args: [ - ethAddress, - DAI_ADDR, - ethAmount, - daiUnitAmount, - getId, - setId - ] - } - ] - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) - let receipt = await tx.wait() - }); - }); -}) \ No newline at end of file