2021-12-11 19:59:54 +00:00
|
|
|
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";
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
describe("Quickswap", function () {
|
|
|
|
const connectorName = "Quickswap-v1";
|
2021-12-11 19:59:54 +00:00
|
|
|
|
|
|
|
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({
|
2021-12-15 12:22:53 +00:00
|
|
|
method: "hardhat_reset",
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
forking: {
|
|
|
|
// @ts-ignore
|
|
|
|
jsonRpcUrl: hre.config.networks.hardhat.forking.url
|
|
|
|
// blockNumber: 13005785
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2021-12-11 19:59:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
masterSigner = await getMasterSigner();
|
2021-12-15 12:22:53 +00:00
|
|
|
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
2021-12-11 19:59:54 +00:00
|
|
|
connector = await deployAndEnableConnector({
|
|
|
|
connectorName,
|
|
|
|
contractArtifact: ConnectV2Quickswap__factory,
|
|
|
|
signer: masterSigner,
|
2021-12-15 12:22:53 +00:00
|
|
|
connectors: instaConnectorsV2
|
2021-12-11 19:59:54 +00:00
|
|
|
});
|
|
|
|
console.log("Connector address", connector.address);
|
|
|
|
});
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
it("Should have contracts deployed.", async function () {
|
2021-12-11 19:59:54 +00:00
|
|
|
expect(!!instaConnectorsV2.address).to.be.true;
|
|
|
|
expect(!!connector.address).to.be.true;
|
|
|
|
expect(!!(await masterSigner.getAddress())).to.be.true;
|
|
|
|
});
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
describe("DSA wallet setup", function () {
|
|
|
|
it("Should build DSA v2", async function () {
|
2021-12-11 19:59:54 +00:00
|
|
|
dsaWallet0 = await buildDSAv2(wallet0.address);
|
|
|
|
expect(!!dsaWallet0.address).to.be.true;
|
|
|
|
});
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
it("Deposit ETH & DAI into DSA wallet", async function () {
|
2021-12-11 19:59:54 +00:00
|
|
|
await wallet0.sendTransaction({
|
|
|
|
to: dsaWallet0.address,
|
2021-12-15 12:22:53 +00:00
|
|
|
value: ethers.utils.parseEther("10")
|
2021-12-11 19:59:54 +00:00
|
|
|
});
|
2021-12-15 12:22:53 +00:00
|
|
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
|
2021-12-11 19:59:54 +00:00
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
await addLiquidity("dai", dsaWallet0.address, ethers.utils.parseEther("10000"));
|
2021-12-11 19:59:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
describe("Main", function () {
|
|
|
|
it("Should deposit successfully", async function () {
|
|
|
|
const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH
|
|
|
|
const daiUnitAmount = ethers.utils.parseEther("1"); // 1 ETH
|
|
|
|
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
2021-12-11 19:59:54 +00:00
|
|
|
|
|
|
|
const getId = "0";
|
|
|
|
const setId = "0";
|
|
|
|
|
|
|
|
const spells = [
|
|
|
|
{
|
|
|
|
connector: connectorName,
|
|
|
|
method: "deposit",
|
2021-12-15 12:22:53 +00:00
|
|
|
args: [ethAddress, DAI_ADDR, ethAmount, daiUnitAmount, "500000000000000000", getId, setId]
|
|
|
|
}
|
2021-12-11 19:59:54 +00:00
|
|
|
];
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
2021-12-11 19:59:54 +00:00
|
|
|
let receipt = await tx.wait();
|
|
|
|
}).timeout(10000000000);
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
it("Should withdraw successfully", async function () {
|
|
|
|
const ethAmount = ethers.utils.parseEther("0.001"); // 1 ETH
|
2021-12-11 19:59:54 +00:00
|
|
|
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
|
|
|
|
|
|
const getId = "0";
|
|
|
|
const setIds = ["0", "0"];
|
|
|
|
|
|
|
|
const spells = [
|
|
|
|
{
|
|
|
|
connector: connectorName,
|
|
|
|
method: "withdraw",
|
2021-12-15 12:22:53 +00:00
|
|
|
args: [ethAddress, DAI_ADDR, ethAmount, 0, 0, getId, setIds]
|
|
|
|
}
|
2021-12-11 19:59:54 +00:00
|
|
|
];
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
2021-12-11 19:59:54 +00:00
|
|
|
let receipt = await tx.wait();
|
|
|
|
});
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
it("Should buy successfully", async function () {
|
2021-12-11 19:59:54 +00:00
|
|
|
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",
|
2021-12-15 12:22:53 +00:00
|
|
|
args: [ethAddress, DAI_ADDR, ethAmount, daiUnitAmount, getId, setId]
|
|
|
|
}
|
2021-12-11 19:59:54 +00:00
|
|
|
];
|
|
|
|
|
2021-12-15 12:22:53 +00:00
|
|
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
|
2021-12-11 19:59:54 +00:00
|
|
|
let receipt = await tx.wait();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|