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