fix testcases

This commit is contained in:
cryptoDev222 2021-09-29 00:19:30 -05:00
parent 99b672d78d
commit 48cf6a02fe
15 changed files with 626 additions and 462 deletions

View File

@ -27,7 +27,7 @@ module.exports = {
version: "0.7.6", version: "0.7.6",
settings: { settings: {
optimizer: { optimizer: {
enabled: false, enabled: true,
runs: 200, runs: 200,
}, },
}, },
@ -63,10 +63,9 @@ module.exports = {
hardhat: { hardhat: {
forking: { forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`, url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
blockNumber: 12796965, blockNumber: 12696000,
}, },
blockGasLimit: 12000000, blockGasLimit: 12000000,
gasPrice: parseInt(utils.parseUnits("300", "gwei"))
}, },
matic: { matic: {
url: "https://rpc-mainnet.maticvigil.com/", url: "https://rpc-mainnet.maticvigil.com/",

View File

@ -13,6 +13,8 @@ const constants = require("../../scripts/constant/constant");
const addLiquidity = require("../../scripts/addLiquidity"); const addLiquidity = require("../../scripts/addLiquidity");
const { ethers } = hre; const { ethers } = hre;
const ALCHEMY_ID = process.env.ALCHEMY_ID;
describe("Aave V1", function() { describe("Aave V1", function() {
const connectorName = "AAVEV1-TEST-A"; const connectorName = "AAVEV1-TEST-A";
@ -23,19 +25,34 @@ describe("Aave V1", function() {
let masterSigner; let masterSigner;
before(async () => { before(async () => {
[wallet0, wallet1] = await ethers.getSigners(); try {
masterSigner = await getMasterSigner(); await hre.network.provider.request({
instaConnectorsV2 = await ethers.getContractAt( method: "hardhat_reset",
abis.core.connectorsV2, params: [
addresses.core.connectorsV2 {
); forking: {
connector = await deployAndEnableConnector({ jsonRpcUrl: hre.config.networks.hardhat.forking.url,
connectorName, blockNumber: 12796965,
contractArtifact: ConnectV2AaveV1, },
signer: masterSigner, },
connectors: instaConnectorsV2, ],
}); });
console.log("Connector address", connector.address); [wallet0, wallet1] = await ethers.getSigners();
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(
abis.core.connectorsV2,
addresses.core.connectorsV2
);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2AaveV1,
signer: masterSigner,
connectors: instaConnectorsV2,
});
console.log("Connector address", connector.address);
} catch (err) {
console.log("error", err);
}
}); });
it("should have contracts deployed", async () => { it("should have contracts deployed", async () => {

View File

@ -23,6 +23,17 @@ describe("Aave V2", function() {
let masterSigner; let masterSigner;
before(async () => { before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 12796965,
},
},
],
});
[wallet0, wallet1] = await ethers.getSigners(); [wallet0, wallet1] = await ethers.getSigners();
masterSigner = await getMasterSigner(); masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt( instaConnectorsV2 = await ethers.getContractAt(

View File

@ -13,7 +13,7 @@ const abis = require("../../scripts/constant/abis");
const constants = require("../../scripts/constant/constant"); const constants = require("../../scripts/constant/constant");
const tokens = require("../../scripts/constant/tokens"); const tokens = require("../../scripts/constant/tokens");
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/compound/main.sol/ConnectV1BCompound.json") const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/compound/main.sol/ConnectV2BCompound.json")
describe("B.Compound", function () { describe("B.Compound", function () {
const connectorName = "B.COMPOUND-TEST-A" const connectorName = "B.COMPOUND-TEST-A"
@ -26,6 +26,17 @@ describe("B.Compound", function () {
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { 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) masterSigner = await getMasterSigner(wallet3)
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({

View File

@ -20,43 +20,54 @@ const LUSD_WHALE = "0x66017D22b0f8556afDd19FC67041899Eb65a21bb" // stability poo
const BAMM_ADDRESS = "0x0d3AbAA7E088C2c82f54B2f47613DA438ea8C598" const BAMM_ADDRESS = "0x0d3AbAA7E088C2c82f54B2f47613DA438ea8C598"
describe("B.Liquity", function () { describe("B.Liquity", function () {
const connectorName = "B.LIQUITY-TEST-A" const connectorName = "B.LIQUITY-TEST-A"
let dsaWallet0;
let dsaWallet1;
let masterSigner;
let instaConnectorsV2;
let connector;
let manager;
let vat;
let lusd;
let bammToken;
let stabilityPool;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => {
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectorLiquityArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
lusd = await ethers.getContractAt("../artifacts/contracts/mainnet/common/interfaces.sol:TokenInterface", "0x5f98805A4E8be255a32880FDeC7F6728C6568bA0") let dsaWallet0;
bammToken = await ethers.getContractAt("../artifacts/contracts/mainnet/connectors/b.protocol/liquity/interface.sol:BAMMLike", BAMM_ADDRESS) let dsaWallet1;
stabilityPool = await ethers.getContractAt("../artifacts/contracts/mainnet/connectors/b.protocol/liquity/interface.sol:StabilityPoolLike", "0x66017D22b0f8556afDd19FC67041899Eb65a21bb") let masterSigner;
let instaConnectorsV2;
let connector;
let manager;
let vat;
let lusd;
let bammToken;
let stabilityPool;
console.log("Connector address", connector.address) 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: 12996875,
},
},
],
});
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectorLiquityArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
lusd = await ethers.getContractAt("../artifacts/contracts/mainnet/common/interfaces.sol:TokenInterface", "0x5f98805A4E8be255a32880FDeC7F6728C6568bA0")
bammToken = await ethers.getContractAt("../artifacts/contracts/mainnet/connectors/b.protocol/liquity/interface.sol:BAMMLike", BAMM_ADDRESS)
stabilityPool = await ethers.getContractAt("../artifacts/contracts/mainnet/connectors/b.protocol/liquity/interface.sol:StabilityPoolLike", "0x66017D22b0f8556afDd19FC67041899Eb65a21bb")
console.log("Connector address", connector.address)
}) })
it("test veryClose.", async function () { it("test veryClose.", async function () {
expect(veryClose(1000001, 1000000)).to.be.true expect(veryClose(1000001, 1000000)).to.be.true
expect(veryClose(1000000, 1000001)).to.be.true expect(veryClose(1000000, 1000001)).to.be.true
expect(veryClose(1003000, 1000001)).to.be.false expect(veryClose(1003000, 1000001)).to.be.false
expect(veryClose(1000001, 1000300)).to.be.false expect(veryClose(1000001, 1000300)).to.be.false
}); });
it("Should have contracts deployed.", async function () { it("Should have contracts deployed.", async function () {
@ -68,44 +79,44 @@ describe("B.Liquity", function () {
describe("DSA wallet setup", function () { describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () { it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.address) dsaWallet0 = await buildDSAv2(wallet0.address)
expect(!!dsaWallet0.address).to.be.true; expect(!!dsaWallet0.address).to.be.true;
dsaWallet1 = await buildDSAv2(wallet1.address) dsaWallet1 = await buildDSAv2(wallet1.address)
expect(!!dsaWallet1.address).to.be.true; expect(!!dsaWallet1.address).to.be.true;
}); });
it("Deposit LUSD into DSA wallet", async function () { it("Deposit LUSD into DSA wallet", async function () {
await hre.network.provider.request({ await hre.network.provider.request({
method: "hardhat_impersonateAccount", method: "hardhat_impersonateAccount",
params: [LUSD_WHALE], params: [LUSD_WHALE],
}); });
const signer = await hre.ethers.provider.getSigner(LUSD_WHALE); const signer = await hre.ethers.provider.getSigner(LUSD_WHALE);
await lusd.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("100000")) await lusd.connect(signer).transfer(dsaWallet0.address, ethers.utils.parseEther("100000"))
expect(await lusd.balanceOf(dsaWallet0.address)).to.equal(ethers.utils.parseEther("100000")); expect(await lusd.balanceOf(dsaWallet0.address)).to.equal(ethers.utils.parseEther("100000"));
}); });
}); });
describe("Main", function () { describe("Main", function () {
it("should deposit 10k LUSD", async function () { it("should deposit 10k LUSD", async function () {
const totalSupplyBefore = await bammToken.totalSupply(); const totalSupplyBefore = await bammToken.totalSupply();
const lusdBalanceBefore = await stabilityPool.getCompoundedLUSDDeposit(BAMM_ADDRESS); const lusdBalanceBefore = await stabilityPool.getCompoundedLUSDDeposit(BAMM_ADDRESS);
const amount = ethers.utils.parseEther("10000"); const amount = ethers.utils.parseEther("10000");
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "deposit", method: "deposit",
args: [amount, 0, 0, 0] args: [amount, 0, 0, 0]
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
const expectedBalance = totalSupplyBefore.mul(amount).div(lusdBalanceBefore) const expectedBalance = totalSupplyBefore.mul(amount).div(lusdBalanceBefore)
expect(veryClose(expectedBalance, await bammToken.balanceOf(dsaWallet0.address))).to.be.true expect(veryClose(expectedBalance, await bammToken.balanceOf(dsaWallet0.address))).to.be.true
}); });
it("should deposit all LUSD", async function () { it("should deposit all LUSD", async function () {
@ -115,11 +126,11 @@ describe("B.Liquity", function () {
const balanceBefore = await bammToken.balanceOf(dsaWallet0.address) const balanceBefore = await bammToken.balanceOf(dsaWallet0.address)
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "deposit", method: "deposit",
args: [amount, 0, 0, 0] args: [amount, 0, 0, 0]
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
@ -128,54 +139,54 @@ describe("B.Liquity", function () {
const expectedBalance = (totalSupplyBefore.mul(ethers.utils.parseEther("90000")).div(lusdBalanceBefore)).add(balanceBefore) const expectedBalance = (totalSupplyBefore.mul(ethers.utils.parseEther("90000")).div(lusdBalanceBefore)).add(balanceBefore)
expect(veryClose(expectedBalance, await bammToken.balanceOf(dsaWallet0.address))).to.be.true expect(veryClose(expectedBalance, await bammToken.balanceOf(dsaWallet0.address))).to.be.true
}); });
it("should withdraw half of the shares", async function () { it("should withdraw half of the shares", async function () {
const balanceBefore = await bammToken.balanceOf(dsaWallet0.address) const balanceBefore = await bammToken.balanceOf(dsaWallet0.address)
const halfBalance = balanceBefore.div("2") const halfBalance = balanceBefore.div("2")
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "withdraw", method: "withdraw",
args: [halfBalance, 0, 0, 0] args: [halfBalance, 0, 0, 0]
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
expect(veryClose(halfBalance, await bammToken.balanceOf(dsaWallet0.address))).to.be.true expect(veryClose(halfBalance, await bammToken.balanceOf(dsaWallet0.address))).to.be.true
expect(veryClose(ethers.utils.parseEther("50000"), await lusd.balanceOf(dsaWallet0.address))).to.be.true expect(veryClose(ethers.utils.parseEther("50000"), await lusd.balanceOf(dsaWallet0.address))).to.be.true
}); });
it("should withdraw all the shares", async function () { it("should withdraw all the shares", async function () {
const amount = web3.utils.toBN("2").pow(web3.utils.toBN("256")).sub(web3.utils.toBN("1")); const amount = web3.utils.toBN("2").pow(web3.utils.toBN("256")).sub(web3.utils.toBN("1"));
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "withdraw", method: "withdraw",
args: [amount, 0, 0, 0] args: [amount, 0, 0, 0]
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
expect(veryClose(ethers.utils.parseEther("100000"), await lusd.balanceOf(dsaWallet0.address))).to.be.true expect(veryClose(ethers.utils.parseEther("100000"), await lusd.balanceOf(dsaWallet0.address))).to.be.true
}); });
}) })
}) })
function veryClose(n1, n2) { function veryClose(n1, n2) {
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) _10000 = web3.utils.toBN(10000)
_9999 = web3.utils.toBN(9999) _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
return true return true
} }

View File

@ -13,23 +13,34 @@ const abis = require("../../scripts/constant/abis");
const constants = require("../../scripts/constant/constant"); const constants = require("../../scripts/constant/constant");
const tokens = require("../../scripts/constant/tokens"); const tokens = require("../../scripts/constant/tokens");
const connectorMakerArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/makerdao/main.sol/ConnectV1BMakerDAO.json") const connectorMakerArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/makerdao/main.sol/ConnectV2BMakerDAO.json")
describe("B.Maker", function () { describe("B.Maker", function () {
const connectorName = "B.MAKER-TEST-A" const connectorName = "B.MAKER-TEST-A"
let dsaWallet0; let dsaWallet0;
let dsaWallet1; let dsaWallet1;
let masterSigner; let masterSigner;
let instaConnectorsV2; let instaConnectorsV2;
let connector; let connector;
let manager; let manager;
let vat; let vat;
let dai; let dai;
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 12696000,
},
},
],
});
masterSigner = await getMasterSigner(wallet3) masterSigner = await getMasterSigner(wallet3)
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({
@ -44,263 +55,263 @@ describe("B.Maker", function () {
dai = await ethers.getContractAt("../artifacts/contracts/mainnet/common/interfaces.sol:TokenInterface", tokens.dai.address) dai = await ethers.getContractAt("../artifacts/contracts/mainnet/common/interfaces.sol:TokenInterface", tokens.dai.address)
console.log("Connector address", connector.address) console.log("Connector address", connector.address)
}) })
it("test veryClose.", async function () { it("test veryClose.", async function () {
expect(veryClose(1000001, 1000000)).to.be.true expect(veryClose(1000001, 1000000)).to.be.true
expect(veryClose(1000000, 1000001)).to.be.true expect(veryClose(1000000, 1000001)).to.be.true
expect(veryClose(1003000, 1000001)).to.be.false expect(veryClose(1003000, 1000001)).to.be.false
expect(veryClose(1000001, 1000300)).to.be.false expect(veryClose(1000001, 1000300)).to.be.false
});
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 connector.name()).to.be.equal("B.MakerDAO-v1.0");
});
describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.address)
expect(!!dsaWallet0.address).to.be.true;
dsaWallet1 = await buildDSAv2(wallet1.address)
expect(!!dsaWallet1.address).to.be.true;
}); });
it("Deposit ETH into DSA wallet", async function () { it("Should have contracts deployed.", async function () {
await wallet0.sendTransaction({ expect(!!instaConnectorsV2.address).to.be.true;
to: dsaWallet0.address, expect(!!connector.address).to.be.true;
value: ethers.utils.parseEther("10") expect(!!masterSigner.address).to.be.true;
expect(await connector.name()).to.be.equal("B.MakerDAO-v1.0");
});
describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.address)
expect(!!dsaWallet0.address).to.be.true;
dsaWallet1 = await buildDSAv2(wallet1.address)
expect(!!dsaWallet1.address).to.be.true;
}); });
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
await wallet1.sendTransaction({ it("Deposit ETH into DSA wallet", async function () {
to: dsaWallet1.address, await wallet0.sendTransaction({
value: ethers.utils.parseEther("10") to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
await wallet1.sendTransaction({
to: dsaWallet1.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10"));
}); });
expect(await ethers.provider.getBalance(dsaWallet1.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () {
let vault
let ilk
let urn
it("Should open ETH-A vault Maker", async function () {
vault = Number(await manager.cdpi()) + 1
const spells = [
{
connector: connectorName,
method: "open",
args: ["ETH-A"]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
expect(await manager.owns(vault)).to.be.equal(dsaWallet0.address)
ilk = await manager.ilks(vault)
expect(ilk).to.be.equal("0x4554482d41000000000000000000000000000000000000000000000000000000")
urn = await manager.urns(vault)
}); });
it("Should deposit", async function () { describe("Main", function () {
const amount = ethers.utils.parseEther("7") // 7 ETH let vault
const setId = "83478237" let ilk
let urn
const spells = [ it("Should open ETH-A vault Maker", async function () {
{ vault = Number(await manager.cdpi()) + 1
connector: connectorName, const spells = [
method: "deposit", {
args: [vault, amount, 0, setId] connector: connectorName,
} method: "open",
] args: ["ETH-A"]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("3")) expect(await manager.owns(vault)).to.be.equal(dsaWallet0.address)
const urnData = await vat.urns(ilk, urn) ilk = await manager.ilks(vault)
expect(urnData[0]).to.be.equal(amount) // ink expect(ilk).to.be.equal("0x4554482d41000000000000000000000000000000000000000000000000000000")
expect(urnData[1]).to.be.equal("0") // art
}); urn = await manager.urns(vault)
});
it("Should withdraw", async function () { it("Should deposit", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH const amount = ethers.utils.parseEther("7") // 7 ETH
const setId = "83478237" const setId = "83478237"
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "withdraw", method: "deposit",
args: [vault, amount, 0, setId] args: [vault, amount, 0, setId]
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("4")) expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("3"))
const urnData = await vat.urns(ilk, urn) const urnData = await vat.urns(ilk, urn)
expect(urnData[0]).to.be.equal(ethers.utils.parseEther("6")) // ink expect(urnData[0]).to.be.equal(amount) // ink
expect(urnData[1]).to.be.equal("0") // art expect(urnData[1]).to.be.equal("0") // art
}); });
it("Should borrow", async function () { it("Should withdraw", async function () {
const amount = ethers.utils.parseEther("6000") // 6000 dai const amount = ethers.utils.parseEther("1") // 1 ETH
const setId = "83478237" const setId = "83478237"
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "borrow", method: "withdraw",
args: [vault, amount, 0, setId] args: [vault, amount, 0, setId]
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
const urnData = await vat.urns(ilk, urn) expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("4"))
expect(urnData[0]).to.be.equal(ethers.utils.parseEther("6")) // ink
expect(urnData[1]).to.be.equal(await daiToArt(vat, ilk, amount)) // art
expect(await dai.balanceOf(dsaWallet0.address)).to.be.equal(amount)
});
it("Should repay", async function () { const urnData = await vat.urns(ilk, urn)
const amount = ethers.utils.parseEther("500") // 500 dai expect(urnData[0]).to.be.equal(ethers.utils.parseEther("6")) // ink
const setId = "83478237" expect(urnData[1]).to.be.equal("0") // art
const spells = [ });
{
connector: connectorName,
method: "payback",
args: [vault, amount, 0, setId]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) it("Should borrow", async function () {
const receipt = await tx.wait() const amount = ethers.utils.parseEther("6000") // 6000 dai
const setId = "83478237"
const urnData = await vat.urns(ilk, urn) const spells = [
expect(urnData[0]).to.be.equal(ethers.utils.parseEther("6")) // ink {
expect(urnData[1]).to.be.equal(await daiToArt(vat, ilk, ethers.utils.parseEther("5500"))) // art connector: connectorName,
expect(await dai.balanceOf(dsaWallet0.address)).to.be.equal(ethers.utils.parseEther("5500")) method: "borrow",
}); args: [vault, amount, 0, setId]
}
]
it("Should depositAndBorrow", async function () { const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const borrowAmount = ethers.utils.parseEther("1000") // 1000 dai const receipt = await tx.wait()
const depositAmount = ethers.utils.parseEther("1") // 1 dai
const setId = "83478237"
const spells = [ const urnData = await vat.urns(ilk, urn)
{ expect(urnData[0]).to.be.equal(ethers.utils.parseEther("6")) // ink
connector: connectorName, expect(urnData[1]).to.be.equal(await daiToArt(vat, ilk, amount)) // art
method: "depositAndBorrow",
args: [vault, depositAmount, borrowAmount, 0, 0, 0, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) expect(await dai.balanceOf(dsaWallet0.address)).to.be.equal(amount)
const receipt = await tx.wait() });
const urnData = await vat.urns(ilk, urn) it("Should repay", async function () {
expect(urnData[0]).to.be.equal(ethers.utils.parseEther("7")) // ink const amount = ethers.utils.parseEther("500") // 500 dai
expect(await dai.balanceOf(dsaWallet0.address)).to.be.equal(ethers.utils.parseEther("6500")) const setId = "83478237"
// calculation is not precise as the jug was dripped
expect(veryClose(urnData[1], await daiToArt(vat, ilk, ethers.utils.parseEther("6500")))).to.be.true
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("1"))
});
it("Should close", async function () { const spells = [
// open a new vault {
const newVault = vault + 1 connector: connectorName,
let spells = [ method: "payback",
{ args: [vault, amount, 0, setId]
connector: connectorName, }
method: "open", ]
args: ["ETH-A"]
}
]
let tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
let receipt = await tx.wait() const receipt = await tx.wait()
expect(await manager.owns(newVault)).to.be.equal(dsaWallet1.address)
ilk = await manager.ilks(newVault) const urnData = await vat.urns(ilk, urn)
expect(ilk).to.be.equal("0x4554482d41000000000000000000000000000000000000000000000000000000") expect(urnData[0]).to.be.equal(ethers.utils.parseEther("6")) // ink
expect(urnData[1]).to.be.equal(await daiToArt(vat, ilk, ethers.utils.parseEther("5500"))) // art
expect(await dai.balanceOf(dsaWallet0.address)).to.be.equal(ethers.utils.parseEther("5500"))
});
urn = await manager.urns(newVault) it("Should depositAndBorrow", async function () {
const borrowAmount = ethers.utils.parseEther("1000") // 1000 dai
const depositAmount = ethers.utils.parseEther("1") // 1 dai
// deposit and borrow const setId = "83478237"
const borrowAmount = ethers.utils.parseEther("6000") // 6000 dai
const depositAmount = ethers.utils.parseEther("5") // 5 ETH
spells = [
{
connector: connectorName,
method: "depositAndBorrow",
args: [newVault, depositAmount, borrowAmount, 0, 0, 0, 0]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address) const spells = [
receipt = await tx.wait() {
connector: connectorName,
method: "depositAndBorrow",
args: [vault, depositAmount, borrowAmount, 0, 0, 0, 0]
}
]
const setId = 0 const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// repay borrow const urnData = await vat.urns(ilk, urn)
spells = [ expect(urnData[0]).to.be.equal(ethers.utils.parseEther("7")) // ink
{ expect(await dai.balanceOf(dsaWallet0.address)).to.be.equal(ethers.utils.parseEther("6500"))
connector: connectorName, // calculation is not precise as the jug was dripped
method: "payback", expect(veryClose(urnData[1], await daiToArt(vat, ilk, ethers.utils.parseEther("6500")))).to.be.true
args: [newVault, borrowAmount, 0, setId] expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("1"))
} });
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address) it("Should close", async function () {
receipt = await tx.wait() // open a new vault
const newVault = vault + 1
let spells = [
{
connector: connectorName,
method: "open",
args: ["ETH-A"]
}
]
// withdraw deposit let tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address)
spells = [ let receipt = await tx.wait()
{
connector: connectorName,
method: "withdraw",
args: [newVault, depositAmount, 0, setId]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address) expect(await manager.owns(newVault)).to.be.equal(dsaWallet1.address)
receipt = await tx.wait()
// close ilk = await manager.ilks(newVault)
spells = [ expect(ilk).to.be.equal("0x4554482d41000000000000000000000000000000000000000000000000000000")
{
connector: connectorName,
method: "close",
args: [newVault]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address) urn = await manager.urns(newVault)
receipt = await tx.wait()
expect(await manager.owns(newVault)).not.to.be.equal(dsaWallet1.address) // deposit and borrow
}); const borrowAmount = ethers.utils.parseEther("6000") // 6000 dai
}) const depositAmount = ethers.utils.parseEther("5") // 5 ETH
spells = [
{
connector: connectorName,
method: "depositAndBorrow",
args: [newVault, depositAmount, borrowAmount, 0, 0, 0, 0]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address)
receipt = await tx.wait()
const setId = 0
// repay borrow
spells = [
{
connector: connectorName,
method: "payback",
args: [newVault, borrowAmount, 0, setId]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address)
receipt = await tx.wait()
// withdraw deposit
spells = [
{
connector: connectorName,
method: "withdraw",
args: [newVault, depositAmount, 0, setId]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address)
receipt = await tx.wait()
// close
spells = [
{
connector: connectorName,
method: "close",
args: [newVault]
}
]
tx = await dsaWallet1.connect(wallet1).cast(...encodeSpells(spells), wallet1.address)
receipt = await tx.wait()
expect(await manager.owns(newVault)).not.to.be.equal(dsaWallet1.address)
});
})
}) })
async function daiToArt(vat, ilk, dai) { async function daiToArt(vat, ilk, dai) {
@ -317,10 +328,10 @@ function veryClose(n1, n2) {
n2 = web3.utils.toBN(n2) n2 = web3.utils.toBN(n2)
_10000 = web3.utils.toBN(10000) _10000 = web3.utils.toBN(10000)
_9999 = web3.utils.toBN(9999) _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
return true return true
} }

View File

@ -2,7 +2,7 @@ const { expect } = require("chai");
const hre = require("hardhat"); const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
const {abi: implementationsABI} = require("../../scripts/constant/abi/core/InstaImplementations.json") const { abi: implementationsABI } = require("../../scripts/constant/abi/core/InstaImplementations.json")
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js") const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../scripts/buildDSAv2") const buildDSAv2 = require("../../scripts/buildDSAv2")
@ -38,6 +38,17 @@ describe("BASIC-ERC1155", function () {
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
},
],
});
await hre.network.provider.request({ await hre.network.provider.request({
method: "hardhat_impersonateAccount", method: "hardhat_impersonateAccount",
params: [TOKEN_OWNER_ADDR], params: [TOKEN_OWNER_ADDR],

View File

@ -2,7 +2,7 @@ const { expect } = require("chai");
const hre = require("hardhat"); const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
const {abi: implementationsABI} = require("../../scripts/constant/abi/core/InstaImplementations.json") const { abi: implementationsABI } = require("../../scripts/constant/abi/core/InstaImplementations.json")
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js") const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../scripts/buildDSAv2") const buildDSAv2 = require("../../scripts/buildDSAv2")
@ -38,6 +38,17 @@ describe("BASIC-ERC721", function () {
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
},
],
});
await hre.network.provider.request({ await hre.network.provider.request({
method: "hardhat_impersonateAccount", method: "hardhat_impersonateAccount",
params: [TOKEN_OWNER_ADDR], params: [TOKEN_OWNER_ADDR],

View File

@ -17,15 +17,26 @@ const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/co
describe("Compound", function () { describe("Compound", function () {
const connectorName = "COMPOUND-TEST-A" const connectorName = "COMPOUND-TEST-A"
let dsaWallet0 let dsaWallet0
let masterSigner; let masterSigner;
let instaConnectorsV2; let instaConnectorsV2;
let connector; let connector;
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { 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) masterSigner = await getMasterSigner(wallet3)
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({
@ -35,93 +46,93 @@ describe("Compound", function () {
connectors: instaConnectorsV2 connectors: instaConnectorsV2
}) })
console.log("Connector address", connector.address) console.log("Connector address", connector.address)
}) })
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(!!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 into DSA wallet", async function () { describe("DSA wallet setup", function () {
await wallet0.sendTransaction({ it("Should build DSA v2", async function () {
to: dsaWallet0.address, dsaWallet0 = await buildDSAv2(wallet0.address)
value: ethers.utils.parseEther("10") expect(!!dsaWallet0.address).to.be.true;
}); });
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () { it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
it("Should deposit ETH in Compound", async function () { to: dsaWallet0.address,
const amount = ethers.utils.parseEther("1") // 1 ETH value: ethers.utils.parseEther("10")
const spells = [ });
{ expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
connector: connectorName, });
method: "deposit",
args: ["ETH-A", amount, 0, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
}); });
it("Should borrow and payback DAI from Compound", async function () { describe("Main", function () {
const amount = ethers.utils.parseEther("100") // 100 DAI
const setId = "83478237"
const spells = [
{
connector: connectorName,
method: "borrow",
args: ["DAI-A", amount, 0, setId]
},
{
connector: connectorName,
method: "payback",
args: ["DAI-A", 0, setId, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) it("Should deposit ETH in Compound", async function () {
const receipt = await tx.wait() const amount = ethers.utils.parseEther("1") // 1 ETH
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9")); const spells = [
}); {
connector: connectorName,
method: "deposit",
args: ["ETH-A", amount, 0, 0]
}
]
it("Should deposit all ETH in Compound", async function () { const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const spells = [ const receipt = await tx.wait()
{ expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
connector: connectorName, });
method: "deposit",
args: ["ETH-A", constants.max_value, 0, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) it("Should borrow and payback DAI from Compound", async function () {
const receipt = await tx.wait() const amount = ethers.utils.parseEther("100") // 100 DAI
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("0")); const setId = "83478237"
}); const spells = [
{
connector: connectorName,
method: "borrow",
args: ["DAI-A", amount, 0, setId]
},
{
connector: connectorName,
method: "payback",
args: ["DAI-A", 0, setId, 0]
}
]
it("Should withdraw all ETH from Compound", async function () { const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const spells = [ const receipt = await tx.wait()
{ expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
connector: connectorName, });
method: "withdraw",
args: ["ETH-A", constants.max_value, 0, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address) it("Should deposit all ETH in Compound", async function () {
const receipt = await tx.wait() const spells = [
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); {
}); connector: connectorName,
}) method: "deposit",
args: ["ETH-A", constants.max_value, 0, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("0"));
});
it("Should withdraw all ETH from Compound", async function () {
const spells = [
{
connector: connectorName,
method: "withdraw",
args: ["ETH-A", constants.max_value, 0, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
})
}) })

View File

@ -17,25 +17,36 @@ const tokens = require("../../scripts/constant/tokens");
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json") const connectV2CompoundArtifacts = require("../../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 let dsaWallet0
let masterSigner; let masterSigner;
let instaConnectorsV2; let instaConnectorsV2;
let connector; let connector;
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { before(async () => {
masterSigner = await getMasterSigner(wallet3) await hre.network.provider.request({
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); method: "hardhat_reset",
connector = await deployAndEnableConnector({ params: [
connectorName, {
contractArtifact: connectV2CompoundArtifacts, forking: {
signer: masterSigner, jsonRpcUrl: hre.config.networks.hardhat.forking.url,
connectors: instaConnectorsV2 blockNumber: 13300000,
}) },
console.log("Connector address", connector.address) },
],
});
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)
}) })
it("Should have contracts deployed.", async function () { it("Should have contracts deployed.", async function () {
@ -46,64 +57,64 @@ describe("Instapool", function () {
describe("DSA wallet setup", function () { describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () { it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.address) dsaWallet0 = await buildDSAv2(wallet0.address)
expect(!!dsaWallet0.address).to.be.true; expect(!!dsaWallet0.address).to.be.true;
}); });
it("Deposit ETH into DSA wallet", async function () { it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({ await wallet0.sendTransaction({
to: dsaWallet0.address, to: dsaWallet0.address,
value: ethers.utils.parseEther("10") value: ethers.utils.parseEther("10")
}); });
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10")); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
}); });
}); });
describe("Main", function () { describe("Main", function () {
it("Should take 100 ETH flashloan from Instapool", async function () { it("Should take 100 ETH flashloan from Instapool", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH const amount = ethers.utils.parseEther("1") // 1 ETH
const flashloanAmount = ethers.utils.parseEther("100") // 100 ETH const flashloanAmount = ethers.utils.parseEther("100") // 100 ETH
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
const IdOne = "2878734423" const IdOne = "2878734423"
const IdTwo = "783243246" const IdTwo = "783243246"
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "deposit", method: "deposit",
args: ["ETH-A", flashloanAmount, 0, IdOne] args: ["ETH-A", flashloanAmount, 0, IdOne]
}, },
{ {
connector: connectorName, connector: connectorName,
method: "withdraw", method: "withdraw",
args: ["ETH-A", amount, IdOne, IdTwo] args: ["ETH-A", amount, IdOne, IdTwo]
}, },
{ {
connector: "INSTAPOOL-A", connector: "INSTAPOOL-A",
method: "flashPayback", method: "flashPayback",
args: [ethAddress, flashloanAmount, IdTwo, 0], args: [ethAddress, flashloanAmount, IdTwo, 0],
} }
] ]
const calldata = encodeFlashcastData(spells); const calldata = encodeFlashcastData(spells);
const spells2 = [ const spells2 = [
{ {
connector: "INSTAPOOL-A", connector: "INSTAPOOL-A",
method: "flashBorrowAndCast", method: "flashBorrowAndCast",
args: [ args: [
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
flashloanAmount, flashloanAmount,
0, // route 0, // route
calldata, calldata,
], ],
} }
] ]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells2), wallet1.address) const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells2), wallet1.address)
const receipt = await tx.wait() const receipt = await tx.wait()
}); });
}) })
}) })

View File

@ -21,6 +21,17 @@ describe("Liquity", () => {
let liquity = null; let liquity = null;
before(async () => { before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
},
],
});
liquity = await helpers.deployAndConnect(contracts, true); liquity = await helpers.deployAndConnect(contracts, true);
expect(liquity.troveManager.address).to.exist; expect(liquity.troveManager.address).to.exist;
expect(liquity.borrowerOperations.address).to.exist; expect(liquity.borrowerOperations.address).to.exist;

View File

@ -20,6 +20,17 @@ describe("Test InstaMapping contract", () => {
const testRoleAddress = "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723"; const testRoleAddress = "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723";
before("get signers", async () => { before("get signers", async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 12796965,
},
},
],
});
[account] = await ethers.getSigners(); [account] = await ethers.getSigners();
const IndexContract = await ethers.getContractAt( const IndexContract = await ethers.getContractAt(
@ -33,6 +44,11 @@ describe("Test InstaMapping contract", () => {
params: [masterAddress], params: [masterAddress],
}); });
await network.provider.send("hardhat_setBalance", [
masterAddress,
"0x1000000000000000000000000",
]);
instaMaster = await ethers.getSigner(masterAddress); instaMaster = await ethers.getSigner(masterAddress);
}); });

View File

@ -51,6 +51,17 @@ describe("UniswapV3", function () {
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { 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) masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"); nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88");
@ -184,7 +195,7 @@ describe("UniswapV3", function () {
const data = await nftManager.positions(tokenIds[0]) const data = await nftManager.positions(tokenIds[0])
expect(data.liquidity).to.be.equals(liquidities[0]); expect(data.liquidity).to.be.equals(liquidities[0]);
}) }).timeout(10000000000);
it("Should deposit successfully", async function () { it("Should deposit successfully", async function () {
const daiAmount = ethers.utils.parseEther("400") // 1 ETH const daiAmount = ethers.utils.parseEther("400") // 1 ETH

View File

@ -48,6 +48,17 @@ describe("UniswapV3", function () {
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { 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) masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"); nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88");

View File

@ -32,6 +32,17 @@ describe("Yearn", function () {
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => { before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 12996975,
},
},
],
});
masterSigner = await getMasterSigner(wallet3) masterSigner = await getMasterSigner(wallet3)
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({