mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	updated tests and scripts
This commit is contained in:
		
							parent
							
								
									5a20afb8f2
								
							
						
					
					
						commit
						dbe2cc2445
					
				| 
						 | 
				
			
			@ -3,7 +3,7 @@ const { web3 } = hre;
 | 
			
		|||
 | 
			
		||||
import { encodeSpells } from "./encodeSpells.js";
 | 
			
		||||
 | 
			
		||||
module.exports = function(spells: any) {
 | 
			
		||||
export default function encodeFlashcastData(spells: any) {
 | 
			
		||||
  const encodeSpellsData = encodeSpells(spells);
 | 
			
		||||
  const targetType = "string[]";
 | 
			
		||||
  let argTypes = [targetType, "bytes[]"];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ function getCurrentCommitSha() {
 | 
			
		|||
// We need to get the current commit sha ourself.
 | 
			
		||||
const sha = getCurrentCommitSha();
 | 
			
		||||
 | 
			
		||||
async function setStatus(context, state, description) {
 | 
			
		||||
async function setStatus(context: any, state: string, description: string) {
 | 
			
		||||
  return fetch(
 | 
			
		||||
    `https://api.github.com/repos/${owner}/${repo}/statuses/${sha}`,
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,11 +44,11 @@ describe("B.Liquity", function () {
 | 
			
		|||
        },
 | 
			
		||||
      ],
 | 
			
		||||
    });
 | 
			
		||||
    masterSigner = await getMasterSigner(wallet3)
 | 
			
		||||
    masterSigner = await getMasterSigner()
 | 
			
		||||
    instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
 | 
			
		||||
    connector = await deployAndEnableConnector({
 | 
			
		||||
      connectorName,
 | 
			
		||||
      contractArtifact: connectorLiquityArtifacts,
 | 
			
		||||
      contractArtifact: ConnectV2BLiquity__factory,
 | 
			
		||||
      signer: masterSigner,
 | 
			
		||||
      connectors: instaConnectorsV2
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +70,7 @@ describe("B.Liquity", function () {
 | 
			
		|||
  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;
 | 
			
		||||
    expect(!!(await masterSigner.getAddress())).to.be.true;
 | 
			
		||||
    expect(await connector.name()).to.be.equal("B.Liquity-v1");
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -175,12 +175,12 @@ describe("B.Liquity", function () {
 | 
			
		|||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
function veryClose(n1, n2) {
 | 
			
		||||
function veryClose(n1: any, n2: any) {
 | 
			
		||||
  n1 = web3.utils.toBN(n1)
 | 
			
		||||
  n2 = web3.utils.toBN(n2)
 | 
			
		||||
 | 
			
		||||
  _10000 = web3.utils.toBN(10000)
 | 
			
		||||
  _9999 = web3.utils.toBN(9999)
 | 
			
		||||
  let _10000 = web3.utils.toBN(10000)
 | 
			
		||||
  let _9999 = web3.utils.toBN(9999)
 | 
			
		||||
 | 
			
		||||
  if (n1.mul(_10000).lt(n2.mul(_9999))) return false
 | 
			
		||||
  if (n2.mul(_10000).lt(n1.mul(_9999))) return false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,25 +3,23 @@ import hre from "hardhat";
 | 
			
		|||
const { web3, deployments, waffle, ethers } = hre;
 | 
			
		||||
const { provider, deployContract } = waffle
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"
 | 
			
		||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
 | 
			
		||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"
 | 
			
		||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
 | 
			
		||||
import { addresses } from "../../../scripts/constant/addresses";
 | 
			
		||||
import { abis } from "../../../scripts/constant/abis";
 | 
			
		||||
import { constants } from "../../../scripts/constant/constant";
 | 
			
		||||
import { tokens } from "../../../scripts/constant/tokens";
 | 
			
		||||
 | 
			
		||||
import connectorMakerArtifacts from ("../../artifacts/contracts/mainnet/connectors/b.protocol/makerdao/main.sol/ConnectV2BMakerDAO.json")
 | 
			
		||||
import { ConnectV2BMakerDAO__factory } from "../../../typechain";
 | 
			
		||||
import type { Signer, Contract } from "ethers";
 | 
			
		||||
 | 
			
		||||
describe("B.Maker", function () {
 | 
			
		||||
    const connectorName = "B.MAKER-TEST-A"
 | 
			
		||||
 | 
			
		||||
    let dsaWallet0: any;
 | 
			
		||||
    let dsaWallet1: any;
 | 
			
		||||
    let masterSigner: any;
 | 
			
		||||
    let instaConnectorsV2: any;
 | 
			
		||||
    let masterSigner: Signer;
 | 
			
		||||
    let instaConnectorsV2: Contract;
 | 
			
		||||
    let connector: any;
 | 
			
		||||
    let manager: any;
 | 
			
		||||
    let vat: any;
 | 
			
		||||
| 
						 | 
				
			
			@ -35,17 +33,18 @@ describe("B.Maker", function () {
 | 
			
		|||
            params: [
 | 
			
		||||
                {
 | 
			
		||||
                    forking: {
 | 
			
		||||
                        // @ts-ignore
 | 
			
		||||
                        jsonRpcUrl: hre.config.networks.hardhat.forking.url,
 | 
			
		||||
                        blockNumber: 12696000,
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            ],
 | 
			
		||||
        });
 | 
			
		||||
        masterSigner = await getMasterSigner(wallet3)
 | 
			
		||||
        masterSigner = await getMasterSigner()
 | 
			
		||||
        instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
 | 
			
		||||
        connector = await deployAndEnableConnector({
 | 
			
		||||
            connectorName,
 | 
			
		||||
            contractArtifact: connectorMakerArtifacts,
 | 
			
		||||
            contractArtifact: ConnectV2BMakerDAO__factory,
 | 
			
		||||
            signer: masterSigner,
 | 
			
		||||
            connectors: instaConnectorsV2
 | 
			
		||||
        })
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +66,7 @@ describe("B.Maker", function () {
 | 
			
		|||
    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;
 | 
			
		||||
        expect(!!(await masterSigner.getAddress())).to.be.true;
 | 
			
		||||
        expect(await connector.name()).to.be.equal("B.MakerDAO-v1.0");
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -96,9 +95,9 @@ describe("B.Maker", function () {
 | 
			
		|||
    });
 | 
			
		||||
 | 
			
		||||
    describe("Main", function () {
 | 
			
		||||
        let vault
 | 
			
		||||
        let ilk
 | 
			
		||||
        let urn
 | 
			
		||||
        let vault: any;
 | 
			
		||||
        let ilk: any;
 | 
			
		||||
        let urn: any;
 | 
			
		||||
 | 
			
		||||
        it("Should open ETH-A vault Maker", async function () {
 | 
			
		||||
            vault = Number(await manager.cdpi()) + 1
 | 
			
		||||
| 
						 | 
				
			
			@ -314,7 +313,7 @@ describe("B.Maker", function () {
 | 
			
		|||
    })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
async function daiToArt(vat, ilk, dai) {
 | 
			
		||||
async function daiToArt(vat: any, ilk: any, dai: any) {
 | 
			
		||||
    const ilks = await vat.ilks(ilk)
 | 
			
		||||
    const rate = ilks[1] // second parameter
 | 
			
		||||
    const _1e27 = ethers.utils.parseEther("1000000000") // 1e9 * 1e18
 | 
			
		||||
| 
						 | 
				
			
			@ -323,12 +322,12 @@ async function daiToArt(vat, ilk, dai) {
 | 
			
		|||
    return art.add(1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function veryClose(n1, n2) {
 | 
			
		||||
function veryClose(n1: any, n2: any) {
 | 
			
		||||
    n1 = web3.utils.toBN(n1)
 | 
			
		||||
    n2 = web3.utils.toBN(n2)
 | 
			
		||||
 | 
			
		||||
    _10000 = web3.utils.toBN(10000)
 | 
			
		||||
    _9999 = web3.utils.toBN(9999)
 | 
			
		||||
    let _10000 = web3.utils.toBN(10000)
 | 
			
		||||
    let _9999 = web3.utils.toBN(9999)
 | 
			
		||||
 | 
			
		||||
    if (n1.mul(_10000).lt(n2.mul(_9999))) return false
 | 
			
		||||
    if (n2.mul(_10000).lt(n1.mul(_9999))) return false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,20 +2,17 @@ import { expect } from "chai"
 | 
			
		|||
import hre from "hardhat"
 | 
			
		||||
const { web3, deployments, waffle, ethers } = hre;
 | 
			
		||||
const { provider, deployContract } = waffle
 | 
			
		||||
import { abi: implementationsABI } from "../../../scripts/constant/abi/core/InstaImplementations.json"
 | 
			
		||||
import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json"
 | 
			
		||||
 | 
			
		||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"
 | 
			
		||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
 | 
			
		||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"
 | 
			
		||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
 | 
			
		||||
 | 
			
		||||
import { addresses } from "../../../scripts/constant/addresses"
 | 
			
		||||
import { abis } from "../../../scripts/constant/abis"
 | 
			
		||||
import { constants } from "../../../scripts/constant/constant"
 | 
			
		||||
import { tokens } from "../../../scripts/constant/tokens"
 | 
			
		||||
import type { Signer, Contract } from "ethers";
 | 
			
		||||
 | 
			
		||||
import connectV2BasicERC1155Artifacts from "../../artifacts/contracts/mainnet/connectors/basic-ERC1155/main.sol/ConnectV2BasicERC1155.json"
 | 
			
		||||
import erc1155Artifacts from "../../artifacts/@openzeppelin/contracts/token/ERC1155/IERC1155.sol/IERC1155.json"
 | 
			
		||||
import { ConnectV2BasicERC1155__factory, IERC1155__factory } from "../../../typechain";
 | 
			
		||||
 | 
			
		||||
const TOKEN_CONTRACT_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
 | 
			
		||||
const TOKEN_OWNER_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
 | 
			
		||||
| 
						 | 
				
			
			@ -27,8 +24,8 @@ describe("BASIC-ERC1155", function () {
 | 
			
		|||
    const connectorName = "BASIC-ERC1155-A"
 | 
			
		||||
 | 
			
		||||
    let dsaWallet0: any;
 | 
			
		||||
    let masterSigner: any;
 | 
			
		||||
    let instaConnectorsV2: any;
 | 
			
		||||
    let masterSigner: Signer;
 | 
			
		||||
    let instaConnectorsV2: Contract;
 | 
			
		||||
    let connector: any;
 | 
			
		||||
    let nftContract: any;
 | 
			
		||||
    let tokenOwner: any;
 | 
			
		||||
| 
						 | 
				
			
			@ -45,6 +42,7 @@ describe("BASIC-ERC1155", function () {
 | 
			
		|||
            params: [
 | 
			
		||||
                {
 | 
			
		||||
                    forking: {
 | 
			
		||||
                         // @ts-ignore
 | 
			
		||||
                        jsonRpcUrl: hre.config.networks.hardhat.forking.url,
 | 
			
		||||
                        blockNumber: 13300000,
 | 
			
		||||
                    },
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +54,7 @@ describe("BASIC-ERC1155", function () {
 | 
			
		|||
            params: [TOKEN_OWNER_ADDR],
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        await network.provider.send("hardhat_setBalance", [
 | 
			
		||||
        await hre.network.provider.send("hardhat_setBalance", [
 | 
			
		||||
            TOKEN_OWNER_ADDR,
 | 
			
		||||
            "0x1000000000000000",
 | 
			
		||||
        ]);
 | 
			
		||||
| 
						 | 
				
			
			@ -65,17 +63,17 @@ describe("BASIC-ERC1155", function () {
 | 
			
		|||
        tokenOwner = await ethers.getSigner(
 | 
			
		||||
            TOKEN_OWNER_ADDR
 | 
			
		||||
        );
 | 
			
		||||
        nftContract = await ethers.getContractAt(erc1155Artifacts.abi, TOKEN_CONTRACT_ADDR)
 | 
			
		||||
        masterSigner = await getMasterSigner(wallet3)
 | 
			
		||||
        nftContract = await ethers.getContractAt(IERC1155__factory.abi, TOKEN_CONTRACT_ADDR)
 | 
			
		||||
        masterSigner = await getMasterSigner()
 | 
			
		||||
        instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
 | 
			
		||||
 | 
			
		||||
        instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
 | 
			
		||||
        instaImplementationsMapping = await ethers.getContractAt(abi, implementationsMappingAddr);
 | 
			
		||||
        InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation")
 | 
			
		||||
        instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
 | 
			
		||||
        await instaAccountV2DefaultImpl.deployed()
 | 
			
		||||
        connector = await deployAndEnableConnector({
 | 
			
		||||
            connectorName,
 | 
			
		||||
            contractArtifact: connectV2BasicERC1155Artifacts,
 | 
			
		||||
            contractArtifact: ConnectV2BasicERC1155__factory,
 | 
			
		||||
            signer: masterSigner,
 | 
			
		||||
            connectors: instaConnectorsV2
 | 
			
		||||
        })
 | 
			
		||||
| 
						 | 
				
			
			@ -85,17 +83,15 @@ describe("BASIC-ERC1155", function () {
 | 
			
		|||
    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;
 | 
			
		||||
        expect(!!(await masterSigner.getAddress())).to.be.true;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe("Implementations", function () {
 | 
			
		||||
 | 
			
		||||
        it("Should add default implementation to mapping.", async function () {
 | 
			
		||||
            const tx = await instaImplementationsMapping.connect(masterSigner).setDefaultImplementation(instaAccountV2DefaultImpl.address);
 | 
			
		||||
            await tx.wait()
 | 
			
		||||
            expect(await instaImplementationsMapping.defaultImplementation()).to.be.equal(instaAccountV2DefaultImpl.address);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe("DSA wallet setup", function () {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,23 +1,18 @@
 | 
			
		|||
import { expect } from "chai";
 | 
			
		||||
import hre from "hardhat";
 | 
			
		||||
import hre, { network } from "hardhat";
 | 
			
		||||
const { web3, deployments, waffle, ethers } = hre;
 | 
			
		||||
const { provider, deployContract } = waffle
 | 
			
		||||
import { abi : implementationsABI } from "../../../scripts/constant/abi/core/InstaImplementations.json"
 | 
			
		||||
 | 
			
		||||
import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json"
 | 
			
		||||
 | 
			
		||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"
 | 
			
		||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
 | 
			
		||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"
 | 
			
		||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import { addresses } from "../../../scripts/constant/addresses"
 | 
			
		||||
import { abis } from "../../../scripts/constant/abis"
 | 
			
		||||
import { constants } from "../../../scripts/constant/constant"
 | 
			
		||||
import { tokens } from "../../../scripts/constant/tokens"
 | 
			
		||||
import type { Signer, Contract } from "ethers";
 | 
			
		||||
 | 
			
		||||
import connectV2BasicERC721Artifacts from "../../artifacts/contracts/mainnet/connectors/basic-ERC721/main.sol/ConnectV2BasicERC721.json"
 | 
			
		||||
import erc721Artifacts from "../../artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.json"
 | 
			
		||||
import { ConnectV2BasicERC721__factory, IERC721__factory } from "../../../typechain";
 | 
			
		||||
 | 
			
		||||
const TOKEN_CONTRACT_ADDR = "0x4d695c615a7aacf2d7b9c481b66045bb2457dfde";
 | 
			
		||||
const TOKEN_OWNER_ADDR = "0x8c6b10d42ff08e56133fca0dac75e1931b1fcc23";
 | 
			
		||||
| 
						 | 
				
			
			@ -29,8 +24,8 @@ describe("BASIC-ERC721", function () {
 | 
			
		|||
    const connectorName = "BASIC-ERC721-A"
 | 
			
		||||
 | 
			
		||||
    let dsaWallet0: any;
 | 
			
		||||
    let masterSigner: any;
 | 
			
		||||
    let instaConnectorsV2: any;
 | 
			
		||||
    let masterSigner: Signer;
 | 
			
		||||
    let instaConnectorsV2: Contract;
 | 
			
		||||
    let connector: any;
 | 
			
		||||
    let nftContract: any;
 | 
			
		||||
    let tokenOwner: any;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,6 +41,7 @@ describe("BASIC-ERC721", function () {
 | 
			
		|||
            params: [
 | 
			
		||||
                {
 | 
			
		||||
                    forking: {
 | 
			
		||||
                        // @ts-ignore
 | 
			
		||||
                        jsonRpcUrl: hre.config.networks.hardhat.forking.url,
 | 
			
		||||
                        blockNumber: 13300000,
 | 
			
		||||
                    },
 | 
			
		||||
| 
						 | 
				
			
			@ -66,17 +62,17 @@ describe("BASIC-ERC721", function () {
 | 
			
		|||
        tokenOwner = await ethers.getSigner(
 | 
			
		||||
            TOKEN_OWNER_ADDR
 | 
			
		||||
        );
 | 
			
		||||
        nftContract = await ethers.getContractAt(erc721Artifacts.abi, TOKEN_CONTRACT_ADDR)
 | 
			
		||||
        masterSigner = await getMasterSigner(wallet3)
 | 
			
		||||
        nftContract = await ethers.getContractAt(IERC721__factory.abi, TOKEN_CONTRACT_ADDR)
 | 
			
		||||
        masterSigner = await getMasterSigner()
 | 
			
		||||
        instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
 | 
			
		||||
 | 
			
		||||
        instaImplementationsMapping = await ethers.getContractAt(implementationsABI, implementationsMappingAddr);
 | 
			
		||||
        instaImplementationsMapping = await ethers.getContractAt(abi, implementationsMappingAddr);
 | 
			
		||||
        InstaAccountV2DefaultImpl = await ethers.getContractFactory("InstaDefaultImplementation")
 | 
			
		||||
        instaAccountV2DefaultImpl = await InstaAccountV2DefaultImpl.deploy(addresses.core.instaIndex);
 | 
			
		||||
        await instaAccountV2DefaultImpl.deployed()
 | 
			
		||||
        connector = await deployAndEnableConnector({
 | 
			
		||||
            connectorName,
 | 
			
		||||
            contractArtifact: connectV2BasicERC721Artifacts,
 | 
			
		||||
            contractArtifact: ConnectV2BasicERC721__factory,
 | 
			
		||||
            signer: masterSigner,
 | 
			
		||||
            connectors: instaConnectorsV2
 | 
			
		||||
        })
 | 
			
		||||
| 
						 | 
				
			
			@ -86,11 +82,10 @@ describe("BASIC-ERC721", function () {
 | 
			
		|||
    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;
 | 
			
		||||
        expect(!!(await masterSigner.getAddress())).to.be.true;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe("Implementations", function () {
 | 
			
		||||
 | 
			
		||||
        it("Should add default implementation to mapping.", async function () {
 | 
			
		||||
            const tx = await instaImplementationsMapping.connect(masterSigner).setDefaultImplementation(instaAccountV2DefaultImpl.address);
 | 
			
		||||
            await tx.wait()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,23 +6,20 @@ const { provider, deployContract } = waffle
 | 
			
		|||
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 encodeFlashcastData from "../../../scripts/tests/encodeFlashcastData.js"
 | 
			
		||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
 | 
			
		||||
 | 
			
		||||
import { addresses } from "../../../scripts/constant/addresses";
 | 
			
		||||
import { abis } from "../../../scripts/constant/abis";
 | 
			
		||||
import { constants } from "../../../scripts/constant/constant";
 | 
			
		||||
import { tokens } from "../../../scripts/constant/tokens";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import connectV2CompoundArtifacts from "../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json"
 | 
			
		||||
import type { Signer, Contract } from "ethers";
 | 
			
		||||
import { ConnectV2Compound__factory } from "../../../typechain";
 | 
			
		||||
 | 
			
		||||
describe("Instapool", function () {
 | 
			
		||||
  const connectorName = "COMPOUND-TEST-A"
 | 
			
		||||
 | 
			
		||||
  let dsaWallet0: any;
 | 
			
		||||
  let masterSigner: any;
 | 
			
		||||
  let instaConnectorsV2: any;
 | 
			
		||||
  let masterSigner: Signer;
 | 
			
		||||
  let instaConnectorsV2: Contract;
 | 
			
		||||
  let connector: any;
 | 
			
		||||
 | 
			
		||||
  const wallets = provider.getWallets()
 | 
			
		||||
| 
						 | 
				
			
			@ -33,17 +30,18 @@ describe("Instapool", function () {
 | 
			
		|||
      params: [
 | 
			
		||||
        {
 | 
			
		||||
          forking: {
 | 
			
		||||
            // @ts-ignore
 | 
			
		||||
            jsonRpcUrl: hre.config.networks.hardhat.forking.url,
 | 
			
		||||
            blockNumber: 13300000,
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
    });
 | 
			
		||||
    masterSigner = await getMasterSigner(wallet3)
 | 
			
		||||
    masterSigner = await getMasterSigner()
 | 
			
		||||
    instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
 | 
			
		||||
    connector = await deployAndEnableConnector({
 | 
			
		||||
      connectorName,
 | 
			
		||||
      contractArtifact: connectV2CompoundArtifacts,
 | 
			
		||||
      contractArtifact: ConnectV2Compound__factory,
 | 
			
		||||
      signer: masterSigner,
 | 
			
		||||
      connectors: instaConnectorsV2
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +51,7 @@ describe("Instapool", function () {
 | 
			
		|||
  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;
 | 
			
		||||
    expect(!!(await masterSigner.getAddress())).to.be.true;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe("DSA wallet setup", function () {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
import hre from "hardhat";
 | 
			
		||||
import { ethers } from "hardhat";
 | 
			
		||||
import hardhatConfig from "../../../hardhat.config";
 | 
			
		||||
 | 
			
		||||
// Instadapp deployment and testing helpers
 | 
			
		||||
| 
						 | 
				
			
			@ -12,34 +13,31 @@ import { instadappAddresses } from "../../../scripts/important/addresses";
 | 
			
		|||
import { instadappAbi } from "../../../scripts/constant/abis";
 | 
			
		||||
 | 
			
		||||
// Instadapp Liquity Connector artifacts
 | 
			
		||||
import connectV2LiquityArtifacts from "../../artifacts/contracts/mainnet/connectors/liquity/main.sol/ConnectV2Liquity.json";
 | 
			
		||||
import connectV2BasicV1Artifacts from "../../artifacts/contracts/mainnet/connectors/basic/main.sol/ConnectV2Basic.json";
 | 
			
		||||
import { ethers } from "hardhat";
 | 
			
		||||
import { ConnectV2Liquity__factory, ConnectV2Basic__factory } from "../../../typechain";
 | 
			
		||||
 | 
			
		||||
// Instadapp uses a fake address to represent native ETH
 | 
			
		||||
import { eth_addr: ETH_ADDRESS } from "../../../scripts/constant/constant";
 | 
			
		||||
import { constants } from "../../../scripts/constant/constant.js";
 | 
			
		||||
import type { Signer, Contract } from "ethers";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const LIQUITY_CONNECTOR = "LIQUITY-v1-TEST";
 | 
			
		||||
const LUSD_GAS_COMPENSATION = hre.ethers.utils.parseUnits("200", 18); // 200 LUSD gas compensation repaid after loan repayment
 | 
			
		||||
const LIQUIDATABLE_TROVES_BLOCK_NUMBER = 12478159; // Deterministic block number for tests to run against, if you change this, tests will break.
 | 
			
		||||
const JUSTIN_SUN_ADDRESS = "0x903d12bf2c57a29f32365917c706ce0e1a84cce3"; // LQTY whale address
 | 
			
		||||
const LIQUIDATABLE_TROVE_ADDRESS = "0xafbeb4cb97f3b08ec2fe07ef0dac15d37013a347"; // Trove which is liquidatable at blockNumber: LIQUIDATABLE_TROVES_BLOCK_NUMBER
 | 
			
		||||
const MAX_GAS = hardhatConfig.networks.hardhat.blockGasLimit; // Maximum gas limit (12000000)
 | 
			
		||||
// const MAX_GAS = hardhatConfig.networks.hardhat.blockGasLimit; // Maximum gas limit (12000000)
 | 
			
		||||
const INSTADAPP_BASIC_V1_CONNECTOR = "Basic-v1";
 | 
			
		||||
 | 
			
		||||
const openTroveSpell = async (
 | 
			
		||||
  dsa,
 | 
			
		||||
  signer: any,
 | 
			
		||||
  dsa: any,
 | 
			
		||||
  signer: Signer,
 | 
			
		||||
  depositAmount: any,
 | 
			
		||||
  borrowAmount: any,
 | 
			
		||||
  upperHint: any,
 | 
			
		||||
  lowerHint: any,
 | 
			
		||||
  maxFeePercentage: any
 | 
			
		||||
) => {
 | 
			
		||||
  let address = signer.address;
 | 
			
		||||
  if (signer.address === undefined) {
 | 
			
		||||
    address = await signer.getAddress();
 | 
			
		||||
  }
 | 
			
		||||
  let address = await signer.getAddress();
 | 
			
		||||
 | 
			
		||||
  const openTroveSpell = {
 | 
			
		||||
    connector: LIQUITY_CONNECTOR,
 | 
			
		||||
| 
						 | 
				
			
			@ -63,9 +61,9 @@ const openTroveSpell = async (
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
const createDsaTrove = async (
 | 
			
		||||
  dsa,
 | 
			
		||||
  signer,
 | 
			
		||||
  liquity,
 | 
			
		||||
  dsa: any,
 | 
			
		||||
  signer: any,
 | 
			
		||||
  liquity: any,
 | 
			
		||||
  depositAmount = hre.ethers.utils.parseEther("5"),
 | 
			
		||||
  borrowAmount = hre.ethers.utils.parseUnits("2000", 18)
 | 
			
		||||
) => {
 | 
			
		||||
| 
						 | 
				
			
			@ -86,32 +84,33 @@ const createDsaTrove = async (
 | 
			
		|||
  );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const sendToken = async (token, amount, from, to) => {
 | 
			
		||||
const sendToken = async (token: any, amount: any, from: any, to: any) => {
 | 
			
		||||
  await hre.network.provider.request({
 | 
			
		||||
    method: "hardhat_impersonateAccount",
 | 
			
		||||
    params: [from],
 | 
			
		||||
  });
 | 
			
		||||
  const signer = await hre.ethers.provider.getSigner(from);
 | 
			
		||||
  const signer = hre.ethers.provider.getSigner(from);
 | 
			
		||||
 | 
			
		||||
  return await token.connect(signer).transfer(to, amount, {
 | 
			
		||||
    gasPrice: 0,
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const resetInitialState = async (walletAddress, contracts, isDebug = false) => {
 | 
			
		||||
const resetInitialState = async (walletAddress: any, contracts: any, isDebug = false) => {
 | 
			
		||||
  const liquity = await deployAndConnect(contracts, isDebug);
 | 
			
		||||
  const dsa = await buildDSAv2(walletAddress);
 | 
			
		||||
 | 
			
		||||
  return [liquity, dsa];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const resetHardhatBlockNumber = async (blockNumber) => {
 | 
			
		||||
const resetHardhatBlockNumber = async (blockNumber: number) => {
 | 
			
		||||
  return await hre.network.provider.request({
 | 
			
		||||
    method: "hardhat_reset",
 | 
			
		||||
    params: [
 | 
			
		||||
      {
 | 
			
		||||
        forking: {
 | 
			
		||||
          jsonRpcUrl: hardhatConfig.networks.hardhat.forking.url,
 | 
			
		||||
          // @ts-ignore
 | 
			
		||||
          jsonRpcUrl: hre.config.networks.hardhat.forking.url,
 | 
			
		||||
          blockNumber,
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
| 
						 | 
				
			
			@ -119,11 +118,11 @@ const resetHardhatBlockNumber = async (blockNumber) => {
 | 
			
		|||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const deployAndConnect = async (contracts, isDebug = false) => {
 | 
			
		||||
const deployAndConnect = async (contracts: any, isDebug = false) => {
 | 
			
		||||
  // Pin Liquity tests to a particular block number to create deterministic state (Ether price etc.)
 | 
			
		||||
  await resetHardhatBlockNumber(LIQUIDATABLE_TROVES_BLOCK_NUMBER);
 | 
			
		||||
  const liquity = {
 | 
			
		||||
    troveManager: null,
 | 
			
		||||
  let liquity = {
 | 
			
		||||
    troveManager: Contract,
 | 
			
		||||
    borrowerOperations: null,
 | 
			
		||||
    stabilityPool: null,
 | 
			
		||||
    lusdToken: null,
 | 
			
		||||
| 
						 | 
				
			
			@ -143,7 +142,7 @@ const deployAndConnect = async (contracts, isDebug = false) => {
 | 
			
		|||
  );
 | 
			
		||||
  const connector = await deployAndEnableConnector({
 | 
			
		||||
    connectorName: LIQUITY_CONNECTOR,
 | 
			
		||||
    contractArtifact: connectV2LiquityArtifacts,
 | 
			
		||||
    contractArtifact: ConnectV2Liquity__factory,
 | 
			
		||||
    signer: masterSigner,
 | 
			
		||||
    connectors: instaConnectorsV2,
 | 
			
		||||
  });
 | 
			
		||||
| 
						 | 
				
			
			@ -152,7 +151,7 @@ const deployAndConnect = async (contracts, isDebug = false) => {
 | 
			
		|||
 | 
			
		||||
  const basicConnector = await deployAndEnableConnector({
 | 
			
		||||
    connectorName: "Basic-v1",
 | 
			
		||||
    contractArtifact: connectV2BasicV1Artifacts,
 | 
			
		||||
    contractArtifact: ConnectV2Basic__factory,
 | 
			
		||||
    signer: masterSigner,
 | 
			
		||||
    connectors: instaConnectorsV2,
 | 
			
		||||
  });
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +225,7 @@ const deployAndConnect = async (contracts, isDebug = false) => {
 | 
			
		|||
  return liquity;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const getTroveInsertionHints = async (depositAmount, borrowAmount, liquity) => {
 | 
			
		||||
const getTroveInsertionHints = async (depositAmount, borrowAmount, liquity: any) => {
 | 
			
		||||
  const nominalCR = await liquity.hintHelpers.computeNominalCR(
 | 
			
		||||
    depositAmount,
 | 
			
		||||
    borrowAmount
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user