2021-12-02 17:31:51 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
import hre from "hardhat";
|
2021-06-24 11:28:01 +00:00
|
|
|
const { web3, deployments, waffle, ethers } = hre;
|
|
|
|
const { provider, deployContract } = waffle
|
|
|
|
|
2021-12-05 19:10:22 +00:00
|
|
|
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"
|
|
|
|
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
|
|
|
|
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"
|
|
|
|
import { encodeFlashcastData } from "../../../scripts/tests/encodeFlashcastData.js"
|
|
|
|
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
|
2021-06-24 11:28:01 +00:00
|
|
|
|
2021-12-02 17:31:51 +00:00
|
|
|
import { addresses } from "../../../scripts/constant/addresses";
|
|
|
|
import { abis } from "../../../scripts/constant/abis";
|
|
|
|
import { constants } from "../../../scripts/constant/constant";
|
|
|
|
import { tokens } from "../../../scripts/constant/tokens";
|
2021-06-24 11:28:01 +00:00
|
|
|
|
2021-12-02 17:31:51 +00:00
|
|
|
|
|
|
|
import connectV2CompoundArtifacts from "../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json"
|
2021-06-24 11:28:01 +00:00
|
|
|
|
|
|
|
describe("Instapool", function () {
|
2021-09-29 05:19:30 +00:00
|
|
|
const connectorName = "COMPOUND-TEST-A"
|
|
|
|
|
2021-12-02 17:31:51 +00:00
|
|
|
let dsaWallet0: any;
|
|
|
|
let masterSigner: any;
|
|
|
|
let instaConnectorsV2: any;
|
|
|
|
let connector: any;
|
2021-09-29 05:19:30 +00:00
|
|
|
|
|
|
|
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: 13300000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
masterSigner = await getMasterSigner(wallet3)
|
|
|
|
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
|
|
|
connector = await deployAndEnableConnector({
|
|
|
|
connectorName,
|
|
|
|
contractArtifact: connectV2CompoundArtifacts,
|
|
|
|
signer: masterSigner,
|
|
|
|
connectors: instaConnectorsV2
|
|
|
|
})
|
|
|
|
console.log("Connector address", connector.address)
|
2021-06-24 11:28:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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 () {
|
2021-09-29 05:19:30 +00:00
|
|
|
dsaWallet0 = await buildDSAv2(wallet0.address)
|
|
|
|
expect(!!dsaWallet0.address).to.be.true;
|
2021-06-24 11:28:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Deposit ETH into DSA wallet", async function () {
|
2021-09-29 05:19:30 +00:00
|
|
|
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"));
|
2021-06-24 11:28:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Main", function () {
|
|
|
|
|
2021-06-24 11:38:42 +00:00
|
|
|
it("Should take 100 ETH flashloan from Instapool", async function () {
|
2021-09-29 05:19:30 +00:00
|
|
|
const amount = ethers.utils.parseEther("1") // 1 ETH
|
|
|
|
const flashloanAmount = ethers.utils.parseEther("100") // 100 ETH
|
|
|
|
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
|
|
|
|
|
|
|
|
const IdOne = "2878734423"
|
|
|
|
const IdTwo = "783243246"
|
|
|
|
|
|
|
|
const spells = [
|
|
|
|
{
|
|
|
|
connector: connectorName,
|
|
|
|
method: "deposit",
|
|
|
|
args: ["ETH-A", flashloanAmount, 0, IdOne]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
connector: connectorName,
|
|
|
|
method: "withdraw",
|
|
|
|
args: ["ETH-A", amount, IdOne, IdTwo]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
connector: "INSTAPOOL-A",
|
|
|
|
method: "flashPayback",
|
|
|
|
args: [ethAddress, flashloanAmount, IdTwo, 0],
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const calldata = encodeFlashcastData(spells);
|
|
|
|
|
|
|
|
const spells2 = [
|
|
|
|
{
|
|
|
|
connector: "INSTAPOOL-A",
|
|
|
|
method: "flashBorrowAndCast",
|
|
|
|
args: [
|
|
|
|
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
|
|
|
|
flashloanAmount,
|
|
|
|
0, // route
|
|
|
|
calldata,
|
|
|
|
],
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells2), wallet1.address)
|
|
|
|
const receipt = await tx.wait()
|
2021-06-24 11:28:01 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|