Merge branch 'typescript-support' of https://github.com/Instadapp/dsa-connectors into typescript-support

This commit is contained in:
pradyuman-verma 2021-12-04 18:41:29 +05:30
commit 67e399f42f
24 changed files with 1801 additions and 1802 deletions

View File

@ -1,28 +1,29 @@
const { expect } = require("chai");
const hre = require("hardhat");
const abis = require("../../../scripts/constant/abis");
const addresses = require("../../../scripts/constant/addresses");
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector");
const getMasterSigner = require("../../../scripts/getMasterSigner");
const buildDSAv2 = require("../../../scripts/buildDSAv2");
const ConnectV2AaveV1 = require("../../artifacts/contracts/mainnet/connectors/aave/v1/main.sol/ConnectV2AaveV1.json");
const { parseEther } = require("@ethersproject/units");
const encodeSpells = require("../../../scripts/encodeSpells");
const tokens = require("../../../scripts/constant/tokens");
const constants = require("../../../scripts/constant/constant");
const addLiquidity = require("../../../scripts/addLiquidity");
const { ethers } = hre;
import { expect } from "chai";
import "hardhat";
import { abis } from "../../../scripts/constant/abis";
import { addresses } from "../../../scripts/constant/addresses";
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/buildDSAv2";
import ConnectV2AaveV1 from "../../artifacts/contracts/mainnet/connectors/aave/v1/main.sol/ConnectV2AaveV1.json";
import { parseEther } from "@ethersproject/units";
import { encodeSpells } from "../../../scripts/encodeSpells";
import { tokens } from "../../../scripts/constant/tokens";
import { constants } from "../../../scripts/constant/constant";
import { addLiquidity } from "../../../scripts/addLiquidity";
// const { ethers } = hre;
const ALCHEMY_ID = process.env.ALCHEMY_ID;
describe("Aave V1", function() {
describe("Aave V1", function () {
const connectorName = "AAVEV1-TEST-A";
let wallet0, wallet1;
let dsaWallet0;
let instaConnectorsV2;
let connector;
let masterSigner;
let wallet0: any, wallet1: any;
let dsaWallet0: any;
let instaConnectorsV2: any;
let connector: any;
let masterSigner: any;
before(async () => {
try {
@ -61,13 +62,13 @@ describe("Aave V1", function() {
expect(!!masterSigner.address).to.be.true;
});
describe("DSA wallet setup", function() {
it("Should build DSA v2", async function() {
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() {
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: parseEther("10"),
@ -78,8 +79,8 @@ describe("Aave V1", function() {
});
});
describe("Main", function() {
it("should deposit ETH in Aave V1", async function() {
describe("Main", function () {
it("should deposit ETH in Aave V1", async function () {
const amt = parseEther("1");
const spells = [
{
@ -100,7 +101,7 @@ describe("Aave V1", function() {
);
});
it("Should borrow and payback DAI from Aave V1", async function() {
it("Should borrow and payback DAI from Aave V1", async function () {
const amt = parseEther("100"); // 100 DAI
// add a little amount of dai to cover any shortfalls
@ -129,7 +130,7 @@ describe("Aave V1", function() {
);
});
it("Should deposit all ETH in Aave V1", async function() {
it("Should deposit all ETH in Aave V1", async function () {
const spells = [
{
connector: connectorName,
@ -147,7 +148,7 @@ describe("Aave V1", function() {
);
});
it("Should withdraw all ETH from Aave V1", async function() {
it("Should withdraw all ETH from Aave V1", async function () {
const spells = [
{
connector: connectorName,

View File

@ -1,26 +1,26 @@
const { expect } = require("chai");
const hre = require("hardhat");
const abis = require("../../scripts/constant/abis");
const addresses = require("../../scripts/constant/addresses");
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector");
const getMasterSigner = require("../../scripts/getMasterSigner");
const buildDSAv2 = require("../../scripts/buildDSAv2");
const ConnectV2AaveV2 = require("../../artifacts/contracts/mainnet/connectors/aave/v2/main.sol/ConnectV2AaveV2.json");
const { parseEther } = require("@ethersproject/units");
const encodeSpells = require("../../scripts/encodeSpells");
const tokens = require("../../scripts/constant/tokens");
const constants = require("../../scripts/constant/constant");
const addLiquidity = require("../../scripts/addLiquidity");
const { ethers } = hre;
import { expect } from "chai";
import hre from "hardhat";
import { abis } from "../../../scripts/constant/abis";
import { addresses } from "../../../scripts/constant/addresses";
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/buildDSAv2";
import { ConnectV2AaveV2 } from "../../artifacts/contracts/mainnet/connectors/aave/v2/main.sol/ConnectV2AaveV2.json";
import { parseEther } from "@ethersproject/units";
import { encodeSpells } from "../../../scripts/encodeSpells";
import { tokens } from "../../../scripts/constant/tokens";
import { constants } from "../../../scripts/constant/constant";
import { addLiquidity } from "../../../scripts/addLiquidity";
// const { ethers } = hre;
describe("Aave V2", function() {
describe("Aave V2", function () {
const connectorName = "AAVEV2-TEST-A";
let wallet0, wallet1;
let dsaWallet0;
let instaConnectorsV2;
let connector;
let masterSigner;
let wallet0: any, wallet1: any;
let dsaWallet0: any;
let instaConnectorsV2: any;
let connector: any;
let masterSigner: any;
before(async () => {
await hre.network.provider.request({
@ -55,13 +55,13 @@ describe("Aave V2", function() {
expect(!!masterSigner.address).to.be.true;
});
describe("DSA wallet setup", function() {
it("Should build DSA v2", async function() {
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() {
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: parseEther("10"),
@ -72,8 +72,8 @@ describe("Aave V2", function() {
});
});
describe("Main", function() {
it("should deposit ETH in Aave V2", async function() {
describe("Main", function () {
it("should deposit ETH in Aave V2", async function () {
const amt = parseEther("1");
const spells = [
{
@ -94,7 +94,7 @@ describe("Aave V2", function() {
);
});
it("Should borrow and payback DAI from Aave V2", async function() {
it("Should borrow and payback DAI from Aave V2", async function () {
const amt = parseEther("100"); // 100 DAI
const setId = "83478237";
const spells = [
@ -119,7 +119,7 @@ describe("Aave V2", function() {
);
});
it("Should borrow and payback half DAI from Aave V2", async function() {
it("Should borrow and payback half DAI from Aave V2", async function () {
const amt = parseEther("100"); // 100 DAI
// const setId = "83478237";
await addLiquidity("dai", dsaWallet0.address, parseEther("1"));
@ -161,7 +161,7 @@ describe("Aave V2", function() {
);
});
it("Should deposit all ETH in Aave V2", async function() {
it("Should deposit all ETH in Aave V2", async function () {
const spells = [
{
connector: connectorName,
@ -179,7 +179,7 @@ describe("Aave V2", function() {
);
});
it("Should withdraw all ETH from Aave V2", async function() {
it("Should withdraw all ETH from Aave V2", async function () {
const spells = [
{
connector: connectorName,

View File

@ -1,139 +0,0 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../scripts/buildDSAv2")
const encodeSpells = require("../../scripts/encodeSpells.js")
const getMasterSigner = require("../../scripts/getMasterSigner")
const addresses = require("../../scripts/constant/addresses");
const abis = require("../../scripts/constant/abis");
const constants = require("../../scripts/constant/constant");
const tokens = require("../../scripts/constant/tokens");
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/compound/main.sol/ConnectV2BCompound.json")
describe("B.Compound", function () {
const connectorName = "B.COMPOUND-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
},
],
});
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2CompoundArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
console.log("Connector address", connector.address)
})
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.Compound-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;
});
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () {
it("Should deposit ETH in Compound", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const spells = [
{
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 () {
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)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
});
it("Should deposit all ETH in Compound", async function () {
const spells = [
{
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

@ -0,0 +1,139 @@
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; //check
const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/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/b.protocol/compound/main.sol/ConnectV2BCompound.json"
describe("B.Compound", function () {
const connectorName = "B.COMPOUND-TEST-A"
let dsaWallet0: any;
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000,
},
},
],
});
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2CompoundArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
console.log("Connector address", connector.address)
})
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.Compound-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;
});
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () {
it("Should deposit ETH in Compound", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const spells = [
{
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 () {
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)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
});
it("Should deposit all ETH in Compound", async function () {
const spells = [
{
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

@ -1,19 +1,18 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre;
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; //check
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../scripts/buildDSAv2")
const encodeSpells = require("../../scripts/encodeSpells.js")
const getMasterSigner = require("../../scripts/getMasterSigner")
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/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";
const addresses = require("../../scripts/constant/addresses");
const abis = require("../../scripts/constant/abis");
const constants = require("../../scripts/constant/constant");
const tokens = require("../../scripts/constant/tokens");
const connectorLiquityArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/liquity/main.sol/ConnectV2BLiquity.json")
import connectorLiquityArtifacts from ("../../artifacts/contracts/mainnet/connectors/b.protocol/liquity/main.sol/ConnectV2BLiquity.json")
const LUSD_WHALE = "0x66017D22b0f8556afDd19FC67041899Eb65a21bb" // stability pool
@ -22,16 +21,16 @@ const BAMM_ADDRESS = "0x0d3AbAA7E088C2c82f54B2f47613DA438ea8C598"
describe("B.Liquity", function () {
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;
let dsaWallet0: any;
let dsaWallet1: any
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
let manager: any;
let vat: any;
let lusd: any;
let bammToken: any;
let stabilityPool: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets

View File

@ -1,31 +1,31 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/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";
const connectorMakerArtifacts = require("../../artifacts/contracts/mainnet/connectors/b.protocol/makerdao/main.sol/ConnectV2BMakerDAO.json")
import connectorMakerArtifacts from ("../../artifacts/contracts/mainnet/connectors/b.protocol/makerdao/main.sol/ConnectV2BMakerDAO.json")
describe("B.Maker", function () {
const connectorName = "B.MAKER-TEST-A"
let dsaWallet0;
let dsaWallet1;
let masterSigner;
let instaConnectorsV2;
let connector;
let manager;
let vat;
let dai;
let dsaWallet0: any;
let dsaWallet1: any;
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
let manager: any;
let vat: any;
let dai: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets

View File

@ -1,21 +1,21 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai"
import hre from "hardhat"
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const { abi: implementationsABI } = require("../../../scripts/constant/abi/core/InstaImplementations.json")
import { abi: implementationsABI } from "../../../scripts/constant/abi/core/InstaImplementations.json"
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/getMasterSigner"
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
import { addresses } from "../../../scripts/constant/addresses"
import { abis } from "../../../scripts/constant/abis"
import { constants } from "../../../scripts/constant/constant"
import { tokens } from "../../../scripts/constant/tokens"
const connectV2BasicERC1155Artifacts = require("../../artifacts/contracts/mainnet/connectors/basic-ERC1155/main.sol/ConnectV2BasicERC1155.json")
const erc1155Artifacts = require("../../artifacts/@openzeppelin/contracts/token/ERC1155/IERC1155.sol/IERC1155.json")
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"
const TOKEN_CONTRACT_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
const TOKEN_OWNER_ADDR = "0x1ca3262009b21F944e6b92a2a88D039D06F1acFa";
@ -26,13 +26,15 @@ const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D"
describe("BASIC-ERC1155", function () {
const connectorName = "BASIC-ERC1155-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let nftContract;
let tokenOwner;
let instaImplementationsMapping;
let dsaWallet0: any;
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
let nftContract: any;
let tokenOwner: any;
let instaImplementationsMapping: any;
let InstaAccountV2DefaultImpl: any;
let instaAccountV2DefaultImpl: any;
const wallets = provider.getWallets()

View File

@ -1,21 +1,23 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const { abi: implementationsABI } = require("../../../scripts/constant/abi/core/InstaImplementations.json")
import { abi : implementationsABI } from "../../../scripts/constant/abi/core/InstaImplementations.json"
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/getMasterSigner"
const connectV2BasicERC721Artifacts = require("../../artifacts/contracts/mainnet/connectors/basic-ERC721/main.sol/ConnectV2BasicERC721.json")
const erc721Artifacts = require("../../artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.json")
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 connectV2BasicERC721Artifacts from "../../artifacts/contracts/mainnet/connectors/basic-ERC721/main.sol/ConnectV2BasicERC721.json"
import erc721Artifacts from "../../artifacts/@openzeppelin/contracts/token/ERC721/IERC721.sol/IERC721.json"
const TOKEN_CONTRACT_ADDR = "0x4d695c615a7aacf2d7b9c481b66045bb2457dfde";
const TOKEN_OWNER_ADDR = "0x8c6b10d42ff08e56133fca0dac75e1931b1fcc23";
@ -26,14 +28,15 @@ const implementationsMappingAddr = "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D"
describe("BASIC-ERC721", function () {
const connectorName = "BASIC-ERC721-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let nftContract;
let tokenOwner;
let instaImplementationsMapping;
let dsaWallet0: any;
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
let nftContract: any;
let tokenOwner: any;
let instaImplementationsMapping: any;
let InstaAccountV2DefaultImpl: any;
let instaAccountV2DefaultImpl: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets

View File

@ -1,27 +1,27 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
import { expect } from "chai";
import hre from "hardhat";
import { web3, deployments, waffle, ethers } = hre;
import { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/getMasterSigner"
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { constants } from "../../../scripts/constant/constant";
import { tokens } from "../../../scripts/constant/tokens";
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json")
import connectV2CompoundArtifacts from "../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json"
describe("Compound", function () {
const connectorName = "COMPOUND-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let dsaWallet0: any;
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets

View File

@ -1,28 +1,29 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const encodeFlashcastData = require("../../../scripts/encodeFlashcastData.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { encodeFlashcastData } from "../../../scripts/encodeFlashcastData.js"
import { getMasterSigner } from "../../../scripts/getMasterSigner"
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { constants } from "../../../scripts/constant/constant";
import { tokens } from "../../../scripts/constant/tokens";
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json")
import connectV2CompoundArtifacts from "../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json"
describe("Instapool", function () {
const connectorName = "COMPOUND-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let dsaWallet0: any;
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets

View File

@ -1,23 +1,23 @@
const hre = require("hardhat");
const hardhatConfig = require("../../../hardhat.config");
import hre from "hardhat";
import hardhatConfig from "../../../hardhat.config";
// Instadapp deployment and testing helpers
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js");
const encodeSpells = require("../../../scripts/encodeSpells.js");
const getMasterSigner = require("../../../scripts/getMasterSigner");
const buildDSAv2 = require("../../../scripts/buildDSAv2");
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/getMasterSigner"
// Instadapp instadappAddresses/ABIs
const instadappAddresses = require("../../../scripts/constant/addresses");
const instadappAbi = require("../../../scripts/constant/abis");
import { instadappAddresses } from "../../../scripts/important/addresses";
import { instadappAbi } from "../../../scripts/constant/abis";
// Instadapp Liquity Connector artifacts
const connectV2LiquityArtifacts = require("../../artifacts/contracts/mainnet/connectors/liquity/main.sol/ConnectV2Liquity.json");
const connectV2BasicV1Artifacts = require("../../artifacts/contracts/mainnet/connectors/basic/main.sol/ConnectV2Basic.json");
const { ethers } = require("hardhat");
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";
// Instadapp uses a fake address to represent native ETH
const { eth_addr: ETH_ADDRESS } = require("../../../scripts/constant/constant");
import { eth_addr: ETH_ADDRESS } from "../../../scripts/constant/constant";
const LIQUITY_CONNECTOR = "LIQUITY-v1-TEST";
const LUSD_GAS_COMPENSATION = hre.ethers.utils.parseUnits("200", 18); // 200 LUSD gas compensation repaid after loan repayment
@ -29,12 +29,12 @@ const INSTADAPP_BASIC_V1_CONNECTOR = "Basic-v1";
const openTroveSpell = async (
dsa,
signer,
depositAmount,
borrowAmount,
upperHint,
lowerHint,
maxFeePercentage
signer: any,
depositAmount: any,
borrowAmount: any,
upperHint: any,
lowerHint: any,
maxFeePercentage: any
) => {
let address = signer.address;
if (signer.address === undefined) {

View File

@ -1,15 +1,15 @@
const hre = require("hardhat");
const { expect } = require("chai");
import hre from "hardhat";
import { expect } from "chai";
// Instadapp deployment and testing helpers
const buildDSAv2 = require("../../scripts/buildDSAv2");
const encodeSpells = require("../../scripts/encodeSpells.js");
import { buildDSAv2 } from "../../../scripts/buildDSAv2";
import { encodeSpells } from "../../../scripts/encodeSpells.js";
// Liquity smart contracts
const contracts = require("./liquity.contracts");
import contracts from "./liquity.contracts";
// Liquity helpers
const helpers = require("./liquity.helpers");
import helpers from "./liquity.helpers";
describe("Liquity", () => {
const { waffle, ethers } = hre;

View File

@ -1,7 +1,7 @@
const { ethers, network } = require("hardhat");
const chai = require("chai");
const chaiPromise = require("chai-as-promised");
const { solidity } = require("ethereum-waffle");
import { ethers, network } from "hardhat";
import chai from "chai";
import chaiPromise from "chai-as-promised";
import { solidity } from "ethereum-waffle";
chai.use(chaiPromise);
chai.use(solidity);
@ -13,9 +13,9 @@ const getMapping = (address, signer) => {
};
describe("Test InstaMapping contract", () => {
let account, instaMaster;
let mappingAddress;
let masterMapping;
let account: any, instaMaster: any;
let mappingAddress: any;
let masterMapping: any;
const indexInterfaceAddress = "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723";
const testRoleAddress = "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723";

View File

@ -1,420 +0,0 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const ALCHEMY_ID = process.env.ALCHEMY_ID;
const deployAndEnableConnector = require("../../../scripts/polygon/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/polygon/buildDSAv2")
const encodeSpells = require("../../../scripts/polygon/encodeSpells.js")
const getMasterSigner = require("../../../scripts/polygon/getMasterSigner")
const addresses = require("../../../scripts/polygon/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/polygon/constant/constant");
const tokens = require("../../../scripts/polygon/constant/tokens");
const connectV2AaveV2Artifacts = require("../../artifacts/contracts/polygon/connectors/aave/v2/main.sol/ConnectV2AaveV2Polygon.json")
const connectV2PoolTogetherArtifacts = require("../../artifacts/contracts/polygon/connectors/pooltogether/main.sol/ConnectV2PoolTogetherPolygon.json")
const DAI_TOKEN_ADDR = tokens.dai.address // DAI Token
// PoolTogether Address: https://docs.pooltogether.com/resources/networks/matic
const USDC_PRIZE_POOL_ADDR = "0xEE06AbE9e2Af61cabcb13170e01266Af2DEFa946" // USDC Prize Pool
const PT_USDC_TICKET_ADDR = "0x473E484c722EF9ec6f63B509b07Bb9cfB258820b" // PT USDC Ticket
const PT_USDC_SPONGSOR_TICKET_ADDR = "0x19c0e557ee5a9b456f613ba3d025a4dc45b52c35" // PT USDC Sponsor Ticket
const USDC_POOL_FAUCET_ADDR = "0x6cbc003fE015D753180f072d904bA841b2415498" // USDC POOL Faucet
const POOL_TOKEN_ADDRESS = "0x25788a1a171ec66Da6502f9975a15B609fF54CF6" // POOL Tocken
const TOKEN_FAUCET_PROXY_FACTORY_ADDR = "0xeaa636304a7C8853324B6b603dCdE55F92dfbab1" // TokenFaucetProxyFactory for claimAll
// Community WETH Prize Pool (Rari): https://reference-app.pooltogether.com/pools/mainnet/0xa88ca010b32a54d446fc38091ddbca55750cbfc3/manage#stats
const WETH_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3" // Community WETH Prize Pool (Rari)
const WETH_POOL_TICKET_ADDR = "0x9b5c30aeb9ce2a6a121cea9a85bc0d662f6d9b40" // Community WETH Prize Pool Ticket (Rari)
const prizePoolABI = [
"function calculateEarlyExitFee( address from, address controlledToken, uint256 amount) external returns ( uint256 exitFee, uint256 burnedCredit)",
"function creditPlanOf( address controlledToken) external view returns ( uint128 creditLimitMantissa, uint128 creditRateMantissa)"
]
const connectorsABI = [
"function isConnectors(string[] calldata connectorNames) external view returns (bool, address[] memory)"
]
describe("PoolTogether", function () {
const connectorName = "AAVEV2-TEST-A"
const ptConnectorName = "POOLTOGETHER-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let ptConnector;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`,
blockNumber: 18717337,
},
},
],
});
masterSigner = await getMasterSigner()
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
// Deploy and enable Compound Connector
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2AaveV2Artifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
// Deploy and enable Pool Together Connector
ptConnector = await deployAndEnableConnector({
connectorName: ptConnectorName,
contractArtifact: connectV2PoolTogetherArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!ptConnector.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 1000 MATIC into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("1000")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("1000"));
});
});
describe("Main - USDC Prize Pool Test", function () {
it("Should deposit 100 MATIC in AAVE V2", async function () {
const amount = ethers.utils.parseEther("100") // 100 MATIC
const spells = [
{
connector: connectorName,
method: "deposit",
args: [tokens.matic.address, amount, 0, 0]
}
]
const tx = await dsaWallet0.cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("900"));
});
it("Should borrow 10 USDC from AAVE V2 and deposit USDC into USDC Prize Pool", async function () {
const amount = ethers.utils.parseUnits("10", 6) // 10 USDC
const setId = "83478237"
const spells = [
{
connector: connectorName,
method: "borrow",
args: [tokens.usdc.address, amount, 2, 0, setId]
},
{
connector: ptConnectorName,
method: "depositTo",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, setId, 0]
}
]
// Before Spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance is 0`).to.be.eq(ethers.utils.parseUnits("0", 6));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_SPONGSOR_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance,`PoolTogether USDC Ticket balance is 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `Expect USDC balance to still equal 0 since it was deposited into Prize Pool`).to.be.eq(0);
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket balance equals 10`).to.be.eq(ethers.utils.parseUnits("10", 6));
// ETH used for transaction
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("900"));
});
it("Should wait 11 days, withdraw all PrizePool, get back 10 USDC, and claim POOL", async function () {
const amount = ethers.utils.parseUnits("10", 6) // 10 USDC
let prizePoolContract = new ethers.Contract(USDC_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
// const { creditLimitMantissa, creditRateMantissa } = await prizePoolContract.creditPlanOf(PT_USDC_TICKET_ADDR);
// console.log("CreditLimitMantiss: ", creditLimitMantissa.toString());
// console.log("CreditRateMantiss: ", creditRateMantissa.toString());
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_USDC_SPONGSOR_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 USDC because 0% fee for sponsorship ticket").to.be.eq(ethers.utils.parseUnits("0", 6));
const spells = [
{
connector: ptConnectorName,
method: "claim",
args: [USDC_POOL_FAUCET_ADDR, 0]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
}
]
// Before spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance equals 0`).to.be.eq(ethers.utils.parseEther("0"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_SPONGSOR_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket is 10`).to.be.eq(ethers.utils.parseUnits("10", 6));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token equals 0`).to.be.eq(ethers.utils.parseEther("0"));
// Increase time by 11 days so we get back all USDC without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [15*24*60*60]);
await ethers.provider.send("evm_mine");
earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_USDC_SPONGSOR_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 DAI because past 14 days").to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
console.log("USDC BALANCE: ", usdcBalance.toString());
console.log("USDC BALANCE: ", ethers.utils.parseUnits("10", 6).toString());
expect(usdcBalance,
`USDC balance to be equal to 10, because of no early withdrawal fee`
).to.be.eq(ethers.utils.parseUnits("10", 6));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
console.log("POOL BALANCE AFTER:" ,poolBalanceAfter.toString());
expect(poolBalanceAfter, `POOL Token Balance to be greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit and withdraw all PrizePool, get back less than 10 USDC", async function() {
const amount = ethers.utils.parseUnits("10", 6) // 10 USDC
const exitFee = ethers.utils.parseUnits(".1", 6) // 1 USDC is 1% of 100 USDC
const spells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_TICKET_ADDR, 0, 0]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_TICKET_ADDR, exitFee, 0, 0]
}
]
// Before spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC Balance equals 100`).to.be.eq(ethers.utils.parseUnits("10", 6));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket equals 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `PoolTogether Token greater than 0`).to.be.gt(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance,
`USDC balance to be less than 10, because of early withdrawal fee`
).to.be.lt(ethers.utils.parseUnits("10",6));
console.log("USDC BALANCE AFTER:", usdcBalance.toString());
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token Balance to greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit, wait 11 days, and withdraw all PrizePool, get 10 USDC, and claim all POOL using claimAll", async function() {
const amount = ethers.utils.parseUnits("9.9", 6) // 9 USDC
const depositSpells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, 0, 0]
}
]
// Before spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance less than 10`).to.be.lt(ethers.utils.parseUnits("10", 6));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_SPONGSOR_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket equal 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token is greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpells), wallet1.address)
const receipt = await tx.wait()
const prizePoolContract = new ethers.Contract(USDC_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_USDC_SPONGSOR_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 USDC because fee 0%").to.be.eq(0);
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11*24*60*60]);
await ethers.provider.send("evm_mine");
const withdrawSpells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claimAll",
args: [TOKEN_FAUCET_PROXY_FACTORY_ADDR, [USDC_POOL_FAUCET_ADDR]]
}
]
// Run spell transaction
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpells), wallet1.address)
const receipt2 = await tx2.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance equals 9.9`).to.be.eq(ethers.utils.parseUnits("9.9", 6));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket equal 0`).to.be.eq(0);
// Expect
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
console.log("POOL BALANCE AFTER:" ,poolBalanceAfter.toString());
expect(poolBalanceAfter, `Pool Token to be greater than before`).to.be.gt(poolBalance);
});
// })
// NO WMATIC POOLS: https://reference-app.pooltogether.com/pools/polygon
// describe("Main - WETH Prize Pool Test", function () {
// it("Deposit 1 ETH into WETH Prize Pool and withdraw immediately", async function () {
// const amount = ethers.utils.parseEther("1") // 1 ETH
// const setId = "83478237"
// const spells = [
// {
// connector: ptConnectorName,
// method: "depositTo",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, setId]
// },
// {
// connector: ptConnectorName,
// method: "withdrawInstantlyFrom",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, setId, 0]
// },
// ]
// // Before Spell
// const ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// // Run spell transaction
// const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
// const receipt = await tx.wait()
// // After spell
// const ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// // ETH used for transaction
// expect(ethBalanceAfter, `ETH Balance less than before spell because of early withdrawal fee`).to.be.lte(ethBalanceBefore);
// });
// it("Deposit 1 ETH into WETH Prize Pool, wait 14 days, then withdraw", async function () {
// const amount = ethers.utils.parseEther("1") // 1 ETH
// const depositSpell = [
// {
// connector: ptConnectorName,
// method: "depositTo",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, 0]
// }
// ]
// const withdrawSpell = [
// {
// connector: ptConnectorName,
// method: "withdrawInstantlyFrom",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, 0, 0]
// }
// ]
// // Before Deposit Spell
// let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// // Run deposit spell transaction
// const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpell), wallet1.address)
// const receipt = await tx.wait()
// // After Deposit spell
// let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// expect(ethBalanceAfter, `ETH Balance less than before spell`).to.be.lte(ethBalanceBefore);
// // Increase time by 11 days so we get back all ETH without early withdrawal fee
// await ethers.provider.send("evm_increaseTime", [14*24*60*60]);
// await ethers.provider.send("evm_mine");
// // Run withdraw spell transaction
// const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpell), wallet1.address)
// const receipt2 = await tx.wait()
// // After Deposit spell
// ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// expect(ethBalanceAfter, `ETH Balance equal to before spell because no early exit fee`).to.be.eq(ethBalanceBefore);
// });
});
})

View File

@ -0,0 +1,422 @@
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const ALCHEMY_ID = process.env.ALCHEMY_ID;
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/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 connectV2AaveV2Artifacts from "../../artifacts/contracts/polygon/connectors/aave/v2/main.sol/ConnectV2AaveV2Polygon.json"
import connectV2PoolTogetherArtifacts from "../../artifacts/contracts/polygon/connectors/pooltogether/main.sol/ConnectV2PoolTogetherPolygon.json"
const DAI_TOKEN_ADDR = tokens.dai.address // DAI Token
// PoolTogether Address: https://docs.pooltogether.com/resources/networks/matic
const USDC_PRIZE_POOL_ADDR = "0xEE06AbE9e2Af61cabcb13170e01266Af2DEFa946" // USDC Prize Pool
const PT_USDC_TICKET_ADDR = "0x473E484c722EF9ec6f63B509b07Bb9cfB258820b" // PT USDC Ticket
const PT_USDC_SPONGSOR_TICKET_ADDR = "0x19c0e557ee5a9b456f613ba3d025a4dc45b52c35" // PT USDC Sponsor Ticket
const USDC_POOL_FAUCET_ADDR = "0x6cbc003fE015D753180f072d904bA841b2415498" // USDC POOL Faucet
const POOL_TOKEN_ADDRESS = "0x25788a1a171ec66Da6502f9975a15B609fF54CF6" // POOL Tocken
const TOKEN_FAUCET_PROXY_FACTORY_ADDR = "0xeaa636304a7C8853324B6b603dCdE55F92dfbab1" // TokenFaucetProxyFactory for claimAll
// Community WETH Prize Pool (Rari): https://reference-app.pooltogether.com/pools/mainnet/0xa88ca010b32a54d446fc38091ddbca55750cbfc3/manage#stats
const WETH_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3" // Community WETH Prize Pool (Rari)
const WETH_POOL_TICKET_ADDR = "0x9b5c30aeb9ce2a6a121cea9a85bc0d662f6d9b40" // Community WETH Prize Pool Ticket (Rari)
const prizePoolABI = [
"function calculateEarlyExitFee( address from, address controlledToken, uint256 amount) external returns ( uint256 exitFee, uint256 burnedCredit)",
"function creditPlanOf( address controlledToken) external view returns ( uint128 creditLimitMantissa, uint128 creditRateMantissa)"
]
const connectorsABI = [
"function isConnectors(string[] calldata connectorNames) external view returns (bool, address[] memory)"
]
describe("PoolTogether", function () {
const connectorName = "AAVEV2-TEST-A"
const ptConnectorName = "POOLTOGETHER-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let ptConnector;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`,
blockNumber: 18717337,
},
},
],
});
masterSigner = await getMasterSigner()
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
// Deploy and enable Compound Connector
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2AaveV2Artifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
// Deploy and enable Pool Together Connector
ptConnector = await deployAndEnableConnector({
connectorName: ptConnectorName,
contractArtifact: connectV2PoolTogetherArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!ptConnector.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 1000 MATIC into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("1000")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("1000"));
});
});
describe("Main - USDC Prize Pool Test", function () {
it("Should deposit 100 MATIC in AAVE V2", async function () {
const amount = ethers.utils.parseEther("100") // 100 MATIC
const spells = [
{
connector: connectorName,
method: "deposit",
args: [tokens.matic.address, amount, 0, 0]
}
]
const tx = await dsaWallet0.cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("900"));
});
it("Should borrow 10 USDC from AAVE V2 and deposit USDC into USDC Prize Pool", async function () {
const amount = ethers.utils.parseUnits("10", 6) // 10 USDC
const setId = "83478237"
const spells = [
{
connector: connectorName,
method: "borrow",
args: [tokens.usdc.address, amount, 2, 0, setId]
},
{
connector: ptConnectorName,
method: "depositTo",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, setId, 0]
}
]
// Before Spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance is 0`).to.be.eq(ethers.utils.parseUnits("0", 6));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_SPONGSOR_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket balance is 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `Expect USDC balance to still equal 0 since it was deposited into Prize Pool`).to.be.eq(0);
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket balance equals 10`).to.be.eq(ethers.utils.parseUnits("10", 6));
// ETH used for transaction
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("900"));
});
it("Should wait 11 days, withdraw all PrizePool, get back 10 USDC, and claim POOL", async function () {
const amount = ethers.utils.parseUnits("10", 6) // 10 USDC
let prizePoolContract = new ethers.Contract(USDC_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
// const { creditLimitMantissa, creditRateMantissa } = await prizePoolContract.creditPlanOf(PT_USDC_TICKET_ADDR);
// console.log("CreditLimitMantiss: ", creditLimitMantissa.toString());
// console.log("CreditRateMantiss: ", creditRateMantissa.toString());
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_USDC_SPONGSOR_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 USDC because 0% fee for sponsorship ticket").to.be.eq(ethers.utils.parseUnits("0", 6));
const spells = [
{
connector: ptConnectorName,
method: "claim",
args: [USDC_POOL_FAUCET_ADDR, 0]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
}
]
// Before spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance equals 0`).to.be.eq(ethers.utils.parseEther("0"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_SPONGSOR_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket is 10`).to.be.eq(ethers.utils.parseUnits("10", 6));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token equals 0`).to.be.eq(ethers.utils.parseEther("0"));
// Increase time by 11 days so we get back all USDC without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [15 * 24 * 60 * 60]);
await ethers.provider.send("evm_mine");
earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_USDC_SPONGSOR_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 DAI because past 14 days").to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
console.log("USDC BALANCE: ", usdcBalance.toString());
console.log("USDC BALANCE: ", ethers.utils.parseUnits("10", 6).toString());
expect(usdcBalance,
`USDC balance to be equal to 10, because of no early withdrawal fee`
).to.be.eq(ethers.utils.parseUnits("10", 6));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
console.log("POOL BALANCE AFTER:", poolBalanceAfter.toString());
expect(poolBalanceAfter, `POOL Token Balance to be greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit and withdraw all PrizePool, get back less than 10 USDC", async function () {
const amount = ethers.utils.parseUnits("10", 6) // 10 USDC
const exitFee = ethers.utils.parseUnits(".1", 6) // 1 USDC is 1% of 100 USDC
const spells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_TICKET_ADDR, 0, 0]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_TICKET_ADDR, exitFee, 0, 0]
}
]
// Before spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC Balance equals 100`).to.be.eq(ethers.utils.parseUnits("10", 6));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket equals 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `PoolTogether Token greater than 0`).to.be.gt(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance,
`USDC balance to be less than 10, because of early withdrawal fee`
).to.be.lt(ethers.utils.parseUnits("10", 6));
console.log("USDC BALANCE AFTER:", usdcBalance.toString());
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token Balance to greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit, wait 11 days, and withdraw all PrizePool, get 10 USDC, and claim all POOL using claimAll", async function () {
const amount = ethers.utils.parseUnits("9.9", 6) // 9 USDC
const depositSpells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, 0, 0]
}
]
// Before spell
let usdcToken = await ethers.getContractAt(abis.basic.erc20, tokens.usdc.address)
let usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance less than 10`).to.be.lt(ethers.utils.parseUnits("10", 6));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_USDC_SPONGSOR_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether USDC Ticket equal 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token is greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpells), wallet1.address)
const receipt = await tx.wait()
const prizePoolContract = new ethers.Contract(USDC_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_USDC_SPONGSOR_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 USDC because fee 0%").to.be.eq(0);
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11 * 24 * 60 * 60]);
await ethers.provider.send("evm_mine");
const withdrawSpells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [USDC_PRIZE_POOL_ADDR, amount, PT_USDC_SPONGSOR_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claimAll",
args: [TOKEN_FAUCET_PROXY_FACTORY_ADDR, [USDC_POOL_FAUCET_ADDR]]
}
]
// Run spell transaction
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpells), wallet1.address)
const receipt2 = await tx2.wait()
// After spell
usdcBalance = await usdcToken.balanceOf(dsaWallet0.address);
expect(usdcBalance, `USDC balance equals 9.9`).to.be.eq(ethers.utils.parseUnits("9.9", 6));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether USDC Ticket equal 0`).to.be.eq(0);
// Expect
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
console.log("POOL BALANCE AFTER:", poolBalanceAfter.toString());
expect(poolBalanceAfter, `Pool Token to be greater than before`).to.be.gt(poolBalance);
});
// })
// NO WMATIC POOLS: https://reference-app.pooltogether.com/pools/polygon
// describe("Main - WETH Prize Pool Test", function () {
// it("Deposit 1 ETH into WETH Prize Pool and withdraw immediately", async function () {
// const amount = ethers.utils.parseEther("1") // 1 ETH
// const setId = "83478237"
// const spells = [
// {
// connector: ptConnectorName,
// method: "depositTo",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, setId]
// },
// {
// connector: ptConnectorName,
// method: "withdrawInstantlyFrom",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, setId, 0]
// },
// ]
// // Before Spell
// const ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// // Run spell transaction
// const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
// const receipt = await tx.wait()
// // After spell
// const ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// // ETH used for transaction
// expect(ethBalanceAfter, `ETH Balance less than before spell because of early withdrawal fee`).to.be.lte(ethBalanceBefore);
// });
// it("Deposit 1 ETH into WETH Prize Pool, wait 14 days, then withdraw", async function () {
// const amount = ethers.utils.parseEther("1") // 1 ETH
// const depositSpell = [
// {
// connector: ptConnectorName,
// method: "depositTo",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, 0]
// }
// ]
// const withdrawSpell = [
// {
// connector: ptConnectorName,
// method: "withdrawInstantlyFrom",
// args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, 0, 0]
// }
// ]
// // Before Deposit Spell
// let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// // Run deposit spell transaction
// const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpell), wallet1.address)
// const receipt = await tx.wait()
// // After Deposit spell
// let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// expect(ethBalanceAfter, `ETH Balance less than before spell`).to.be.lte(ethBalanceBefore);
// // Increase time by 11 days so we get back all ETH without early withdrawal fee
// await ethers.provider.send("evm_increaseTime", [14*24*60*60]);
// await ethers.provider.send("evm_mine");
// // Run withdraw spell transaction
// const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpell), wallet1.address)
// const receipt2 = await tx.wait()
// // After Deposit spell
// ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// expect(ethBalanceAfter, `ETH Balance equal to before spell because no early exit fee`).to.be.eq(ethBalanceBefore);
// });
});
})

View File

@ -1,811 +0,0 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
const connectV2CompoundArtifacts = require("../../artifacts/contracts/mainnet/connectors/compound/main.sol/ConnectV2Compound.json")
const connectV2PoolTogetherArtifacts = require("../../artifacts/contracts/mainnet/connectors/pooltogether/main.sol/ConnectV2PoolTogether.json")
const connectV2UniswapArtifacts = require("../../artifacts/contracts/mainnet/connectors/uniswap/main.sol/ConnectV2UniswapV2.json")
const DAI_TOKEN_ADDR = tokens.dai.address // DAI Token
// PoolTogether Address: https://docs.pooltogether.com/resources/networks/ethereum
const DAI_PRIZE_POOL_ADDR = "0xEBfb47A7ad0FD6e57323C8A42B2E5A6a4F68fc1a" // DAI Prize Pool
const PT_DAI_TICKET_ADDR = "0x334cBb5858417Aee161B53Ee0D5349cCF54514CF" // PT DAI Ticket
const DAI_POOL_FAUCET_ADDR = "0xF362ce295F2A4eaE4348fFC8cDBCe8d729ccb8Eb" // DAI POOL Faucet
const POOL_TOKEN_ADDRESS = "0x0cEC1A9154Ff802e7934Fc916Ed7Ca50bDE6844e" // POOL Tocken
const TOKEN_FAUCET_PROXY_FACTORY_ADDR = "0xE4E9cDB3E139D7E8a41172C20b6Ed17b6750f117" // TokenFaucetProxyFactory for claimAll
const DAI_POD_ADDR = "0x2f994e2E4F3395649eeE8A89092e63Ca526dA829" // DAI Pod
const UNISWAP_POOLETHLP_PRIZE_POOL_ADDR = "0x3AF7072D29Adde20FC7e173a7CB9e45307d2FB0A" // Uniswap Pool/ETH LP PrizePool
const UNISWAP_POOLETHLP_FAUCET_ADDR = "0x9A29401EF1856b669f55Ae5b24505b3B6fAEb370" // Uniswap Pool/ETH LP Faucet
const UNISWAP_POOLETHLP_TOKEN_ADDR = "0x85cb0bab616fe88a89a35080516a8928f38b518b" // Uniswap Pool/ETH Token
const PT_UNISWAP_POOLETHLP_TICKET_ADDR = "0xeb8928ee92efb06c44d072a24c2bcb993b61e543" // Pool Together Uniswap Pool/ETH LP Ticket
const POOL_PRIZE_POOL_ADDR = "0x396b4489da692788e327e2e4b2b0459a5ef26791" // POOL Prize Pool
const PT_POOL_TICKET_ADDR = "0x27d22a7648e955e510a40bdb058333e9190d12d4" // Pool Together POOL Ticket
const WETH_ADDR = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" // WETH
const DAI_POD_TOKEN_DROP = "0xc5209623E3dFdf9C0cCbe497c8012883C4147731"
// Community WETH Prize Pool (Rari): https://reference-app.pooltogether.com/pools/mainnet/0xa88ca010b32a54d446fc38091ddbca55750cbfc3/manage#stats
const WETH_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3" // Community WETH Prize Pool (Rari)
const WETH_POOL_TICKET_ADDR = "0x9b5c30aeb9ce2a6a121cea9a85bc0d662f6d9b40" // Community WETH Prize Pool Ticket (Rari)
const prizePoolABI = [
"function calculateEarlyExitFee( address from, address controlledToken, uint256 amount) external returns ( uint256 exitFee, uint256 burnedCredit)"
]
const podABI = [
"function getEarlyExitFee(uint256 amount) external returns (uint256)",
"function balanceOfUnderlying(address user) external view returns (uint256 amount)",
"function drop() public returns (uint256)",
"function balanceOf(address account) external view returns (uint256)"
]
const POD_FACTORY_ADDRESS = "0x4e3a9f9fbafb2ec49727cffa2a411f7a0c1c4ce1"
const podFactoryABI = [
"function create( address _prizePool, address _ticket, address _faucet, address _manager, uint8 _decimals) external returns (address pod)"
]
const tokenDropABI = [
"function claim(address user) external returns (uint256)",
]
describe("PoolTogether", function () {
const connectorName = "COMPOUND-TEST-A"
const uniswapConnectorName = "UNISWAP-TEST-A"
const ptConnectorName = "POOLTOGETHER-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let ptConnector;
let uniswapConnector;
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);
// Deploy and enable Compound Connector
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2CompoundArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
// Deploy and enable Pool Together Connector
ptConnector = await deployAndEnableConnector({
connectorName: ptConnectorName,
contractArtifact: connectV2PoolTogetherArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
// Deploy and enable Uniswap Connector
uniswapConnector = await deployAndEnableConnector({
connectorName: uniswapConnectorName,
contractArtifact: connectV2UniswapArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!ptConnector.address).to.be.true;
expect(!!uniswapConnector.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 10 ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main - DAI Prize Pool Test", function () {
it("Should deposit 1 ETH in Compound", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const spells = [
{
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 100 DAI from Compound and deposit DAI into DAI Prize Pool", async 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: ptConnectorName,
method: "depositTo",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, setId, 0]
}
]
// Before Spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance is 0`).to.be.eq(ethers.utils.parseEther("0"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance,`PoolTogether DAI Ticket balance is 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `Expect DAI balance to still equal 0 since it was deposited into Prize Pool`).to.be.eq(0);
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether DAI Ticket balance equals 100`).to.be.eq(ethers.utils.parseEther("100"));
// ETH used for transaction
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
});
it("Should wait 11 days, withdraw all PrizePool, get back 100 DAI, and claim POOL", async function () {
const amount = ethers.utils.parseEther("100") // 100 DAI
let prizePoolContract = new ethers.Contract(DAI_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 1 DAI because starts at 10%").to.be.eq(ethers.utils.parseEther("1"));
const spells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claim",
args: [DAI_POOL_FAUCET_ADDR, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance equals 0`).to.be.eq(ethers.utils.parseEther("0"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether Dai Ticket is 100`).to.be.eq(ethers.utils.parseEther("100"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token equals 0`).to.be.eq(ethers.utils.parseEther("0"));
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11*24*60*60]);
await ethers.provider.send("evm_mine");
earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 DAI because past 10 days").to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance to be equal to 100, because of no early withdrawal fee`
).to.be.eq(ethers.utils.parseEther("100"));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether Dai Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token Balance to be greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit and withdraw all PrizePool, get back less than 100 DAI", async function() {
const amount = ethers.utils.parseEther("100") // 100 DAI
const exitFee = ethers.utils.parseEther("1") // 1 DAI is 10% of 100 DAI
const spells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, 0, 0]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, exitFee, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI Balance equals 0`).to.be.eq(ethers.utils.parseEther("100"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether DAI Ticket equals 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `PoolTogether Token greater than 0`).to.be.gt(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance to be less than 100, because of early withdrawal fee`
).to.be.lt(ethers.utils.parseEther("100"));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether Dai Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token Balance to greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit, wait 11 days, and withdraw all PrizePool, get 99 DAI, and claim all POOL using claimAll", async function() {
const amount = ethers.utils.parseEther("99") // 99 DAI
const depositSpells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance less than 100`).to.be.lt(ethers.utils.parseEther("100"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether DAI Ticket equal 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token is greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpells), wallet1.address)
const receipt = await tx.wait()
const prizePoolContract = new ethers.Contract(DAI_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to .99 DAI because starts at 10%").to.be.eq(ethers.utils.parseEther(".99"));
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11*24*60*60]);
await ethers.provider.send("evm_mine");
earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 DAI because past 10 days").to.be.eq(0);
const withdrawSpells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claimAll",
args: [TOKEN_FAUCET_PROXY_FACTORY_ADDR, [DAI_POOL_FAUCET_ADDR]]
}
]
// Run spell transaction
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpells), wallet1.address)
const receipt2 = await tx2.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance equals 99`).to.be.eq(ethers.utils.parseEther("99"));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether DAI Ticket equal 0`).to.be.eq(0);
// Expect
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `Pool Token to be greateir than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
})
describe("Main - DAI Pod Test", function() {
it("Should deposit 99 DAI in DAI Pod", async function() {
const amount = ethers.utils.parseEther("99") // 99 DAI
const spells = [
{
connector: ptConnectorName,
method: "depositToPod",
args: [DAI_TOKEN_ADDR, DAI_POD_ADDR, amount, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance equals 99`).to.be.eq(ethers.utils.parseEther("99"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR)
const podBalance = await podToken.balanceOf(dsaWallet0.address)
expect(podBalance, `Pod DAI Token equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI equals 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token greater than 0`).to.be.gt(0);
const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address)
expect(podBalanceAfter, `Pod DAI token greater than 0`).to.be.eq(ethers.utils.parseEther("99"));
});
it("Should claim rewards from pod token drop", async function() {
const spells = [
{
connector: ptConnectorName,
method: "claimPodTokenDrop",
args: [DAI_POD_TOKEN_DROP, 0]
}
]
const tokenDropContract = new ethers.Contract(DAI_POD_TOKEN_DROP, tokenDropABI, ethers.provider);
const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, masterSigner);
// drop(): Claim TokenDrop asset for PrizePool Pod and transfers token(s) to external Pod TokenDrop
// dropt() also calls batch which, Deposit Pod float into PrizePool. Deposits the current float
// amount into the PrizePool and claims current POOL rewards.
const dropTx = await podContract.drop();
await dropTx.wait();
// POOL Rewards able to claim from Pod Token Drop
let claimAmount = await tokenDropContract.callStatic["claim"](dsaWallet0.address);
// Before spell
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
const total = claimAmount.add(poolBalance);
expect(poolBalanceAfter, `POOL Token same as before spell`).to.be.eq(total);
});
it("Should wait 11 days, withdraw all podTokens, get back 99 DAI", async function () {
const amount = ethers.utils.parseEther("99") // 99 DAI
const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, ethers.provider);
let maxFee = await podContract.callStatic["getEarlyExitFee"](amount);
// maxFee depends on if token has been deposited to PrizePool yet
// since we called drop in previous test case, the tokens were deposited to PrizePool
expect(maxFee, "Exit Fee equal to .99 DAI because token still in float").to.be.eq(ethers.utils.parseEther(".99"));
const spells = [
{
connector: ptConnectorName,
method: "withdrawFromPod",
args: [DAI_POD_ADDR, amount, maxFee, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI Balance equals 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token balance greater than 0`).to.be.gt(0);
let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR)
const podBalance = await podToken.balanceOf(dsaWallet0.address)
expect(podBalance, `Pod DAI Token equals 99`).to.be.eq(ethers.utils.parseEther("99"));
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11*24*60*60]);
await ethers.provider.send("evm_mine");
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance equals 99, because of no early withdrawal fee`
).to.be.eq(ethers.utils.parseEther("99"));
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token to be greater than 0`).to.be.gt(0);
const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address)
expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(0);
});
it("Should deposit and withdraw from pod, get back same amount of 99 DAI", async function() {
const amount = ethers.utils.parseEther("99")
const maxFee = 0; // maxFee 0 since it doesn't give chance for Pod to actually deposit into PrizePool
const spells = [
{
connector: ptConnectorName,
method: "depositToPod",
args: [DAI_TOKEN_ADDR, DAI_POD_ADDR, amount, 0, 0]
},
{
connector: ptConnectorName,
method: "withdrawFromPod",
args: [DAI_POD_ADDR, amount, maxFee, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI equals 99`).to.be.eq(ethers.utils.parseEther("99"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
// PodToken is 0
let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR)
const podBalance = await podToken.balanceOf(dsaWallet0.address)
expect(podBalance, `Pod DAI Token equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance to be equal to 99, because funds still in 'float`
).to.be.eq(ethers.utils.parseEther("99"));
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token same as before spell`).to.be.eq(poolBalance);
// Expect Pod Token Balance to equal 0
const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address)
expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(ethers.utils.parseEther("0"));
});
})
describe("Main - UNISWAP POOL/ETH Prize Pool Test", function () {
it("Should use uniswap to swap ETH for POOL, deposit to POOL/ETH LP, deposit POOL/ETH LP to PrizePool", async function () {
const amount = ethers.utils.parseEther("100") // 100 POOL
const slippage = ethers.utils.parseEther("0.03");
const setId = "83478237"
const UniswapV2Router02ABI = [
"function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)"
];
// Get amount of ETH for 100 POOL from Uniswap
const UniswapV2Router02 = await ethers.getContractAt(UniswapV2Router02ABI, "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D");
const amounts = await UniswapV2Router02.getAmountsOut(amount, [POOL_TOKEN_ADDRESS, WETH_ADDR]);
const unitAmount = ethers.utils.parseEther(((amounts[1]*1.03)/amounts[0]).toString());
const spells = [
{
connector: uniswapConnectorName,
method: "buy",
args: [POOL_TOKEN_ADDRESS, tokens.eth.address, amount, unitAmount, 0, setId]
},
{
connector: uniswapConnectorName,
method: "deposit",
args: [POOL_TOKEN_ADDRESS, tokens.eth.address, amount, unitAmount, slippage, 0, setId]
},
{
connector: ptConnectorName,
method: "depositTo",
args: [UNISWAP_POOLETHLP_PRIZE_POOL_ADDR, 0, PT_UNISWAP_POOLETHLP_TICKET_ADDR, setId, 0]
}
]
// Before Spell
let ethBalance = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalance, `ETH Balance equals 9`).to.be.eq(ethers.utils.parseEther("9"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
let uniswapLPToken = await ethers.getContractAt(abis.basic.erc20, UNISWAP_POOLETHLP_TOKEN_ADDR)
const uniswapPoolEthBalance = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalance, `Uniswap POOL/ETH LP equals 0`).to.be.eq(0);
let ptUniswapPoolEthToken = await ethers.getContractAt(abis.basic.erc20, PT_UNISWAP_POOLETHLP_TICKET_ADDR)
const ptUniswapPoolEthBalance = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
expect(ptUniswapPoolEthBalance, `PoolTogether Uniswap POOL?ETH LP equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
ethBalance = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalance, `ETH Balance less than 9`).to.be.lt(ethers.utils.parseEther("9"));
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token to be same after spell`).to.be.eq(poolBalance);
const uniswapPoolEthBalanceAfter = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalanceAfter, `Uniswap POOL/ETH LP equals 0`).to.be.eq(0);
const ptUniswapPoolEthBalanceAfter = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
expect(ptUniswapPoolEthBalanceAfter, `PT Uniswap POOL/ETH LP to greater than 0`).to.be.gt(0);
});
it("Should withdraw all PrizePool, get back Uniswap LP, claim POOL, deposit claimed POOL into Pool PrizePool", async function () {
let ptUniswapPoolEthToken = await ethers.getContractAt(abis.basic.erc20, PT_UNISWAP_POOLETHLP_TICKET_ADDR)
const ptUniswapPoolEthBalance = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
const setId = "83478237"
let uniswapPrizePoolContract = new ethers.Contract(UNISWAP_POOLETHLP_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await uniswapPrizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_UNISWAP_POOLETHLP_TICKET_ADDR, ptUniswapPoolEthBalance);
expect(earlyExitFee.exitFee, "Exit Fee equals 0 because no early exit fee for this prize pool").to.be.eq(0);
const spells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [UNISWAP_POOLETHLP_PRIZE_POOL_ADDR, ptUniswapPoolEthBalance, PT_UNISWAP_POOLETHLP_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claim",
args: [UNISWAP_POOLETHLP_FAUCET_ADDR , setId]
},
{
connector: ptConnectorName,
method: "depositTo",
args: [POOL_PRIZE_POOL_ADDR, 0, PT_POOL_TICKET_ADDR, setId, 0]
}
]
// Before spell
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
// Uniswap POOL/ETH LP is 0
let uniswapLPToken = await ethers.getContractAt(abis.basic.erc20, UNISWAP_POOLETHLP_TOKEN_ADDR)
const uniswapPoolEthBalance = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalance, `Uniswap POOL/ETH LP equals 0`).to.be.eq(0);
expect(ptUniswapPoolEthBalance, `PT Uniswap POOL/ETH LP greater than 0`).to.be.gt(0);
let poolPoolTicket = await ethers.getContractAt(abis.basic.erc20, PT_POOL_TICKET_ADDR)
const poolPoolTicketBalance = await poolPoolTicket.balanceOf(dsaWallet0.address)
expect(poolPoolTicketBalance, `PoolTogether POOL Ticket equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `Pool Token Balance equal to balance before spell`).to.be.eq(poolBalance);
const uniswapPoolEthBalanceAfter = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalanceAfter, `Uniswap POOL/ETH LP to greater than 0`).to.be.gt(0);
const ptUniswapPoolEthBalanceAfter = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
expect(ptUniswapPoolEthBalanceAfter, `PT Uniswap POOL/ETH LP equal 0`).to.be.eq(0);
const poolPoolTicketBalanceAfter = await poolPoolTicket.balanceOf(dsaWallet0.address)
expect(poolPoolTicketBalanceAfter, `PoolTogether POOL Ticket greater than 0`).to.be.gt(0);
});
})
describe("Main - WETH Prize Pool Test", function () {
it("Deposit 1 ETH into WETH Prize Pool and withdraw immediately", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const setId = "83478237"
const spells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, setId]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, setId, 0]
},
]
// Before Spell
const ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
const ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// ETH used for transaction
expect(ethBalanceAfter, `ETH Balance less than before spell because of early withdrawal fee`).to.be.lte(ethBalanceBefore);
});
it("Deposit 1 ETH into WETH Prize Pool, wait 14 days, then withdraw", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const depositSpell = [
{
connector: ptConnectorName,
method: "depositTo",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, 0]
}
]
const withdrawSpell = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, 0, 0]
}
]
// Before Deposit Spell
let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run deposit spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpell), wallet1.address)
const receipt = await tx.wait()
// After Deposit spell
let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH Balance less than before spell`).to.be.lte(ethBalanceBefore);
// Increase time by 11 days so we get back all ETH without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [14*24*60*60]);
await ethers.provider.send("evm_mine");
// Run withdraw spell transaction
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpell), wallet1.address)
const receipt2 = await tx.wait()
// After Deposit spell
ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH Balance equal to before spell because no early exit fee`).to.be.eq(ethBalanceBefore);
});
});
describe("Main - WETH Pod Test", function() {
let podAddress
it("Should deposit 1 ETH in WETH Pod and get Pod Ticket", async function() {
const amount = ethers.utils.parseEther("1")
// Create Pod for WETH Prize Pool (Rari)
const podFactoryContract = new ethers.Contract(POD_FACTORY_ADDRESS, podFactoryABI, masterSigner)
podAddress = await podFactoryContract.callStatic.create(WETH_PRIZE_POOL_ADDR, WETH_POOL_TICKET_ADDR, constants.address_zero, wallet0.address, 18)
await podFactoryContract.create(WETH_PRIZE_POOL_ADDR, WETH_POOL_TICKET_ADDR, constants.address_zero, wallet0.address, 18)
const spells = [
{
connector: ptConnectorName,
method: "depositToPod",
args: [WETH_ADDR, podAddress, amount, 0, 0]
}
]
// Before Deposit Spell
const podContract = new ethers.Contract(podAddress, podABI, ethers.provider);
let podBalanceBefore = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceBefore, `Pod balance equal to 0`).to.be.eq(0);
let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After Deposit spell
let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH balance less than before`).to.be.lt(ethBalanceBefore);
podBalanceAfter = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceAfter, `Pod balance equal to 1`).to.be.eq(ethers.utils.parseEther("1"));
});
it("Should withdraw 1 Ticket from WETH Pod and get back ETH", async function() {
const amount = ethers.utils.parseEther("1")
const podContract = new ethers.Contract(podAddress, podABI, ethers.provider);
let maxFee = await podContract.callStatic["getEarlyExitFee"](amount);
expect(maxFee, "Exit Fee equal to 0 DAI because token still in float").to.be.eq(0);
// maxFee depends on if token has been deposited to PrizePool yet
const spells = [
{
connector: ptConnectorName,
method: "withdrawFromPod",
args: [podAddress, amount, maxFee, 0, 0]
}
]
// Before Deposit Spell
let podBalanceBefore = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceBefore, `Pod balance equal to 1`).to.be.eq(ethers.utils.parseEther("1"));
let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After Deposit spell
let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH balance greater than before`).to.be.gt(ethBalanceBefore);
podBalanceAfter = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceAfter, `Pod balance equal to 0`).to.be.eq(ethers.utils.parseEther("0"));
});
});
})

View File

@ -0,0 +1,811 @@
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/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 connectV2PoolTogetherArtifacts from "../../artifacts/contracts/mainnet/connectors/pooltogether/main.sol/ConnectV2PoolTogether.json"
import connectV2UniswapArtifacts from "../../artifacts/contracts/mainnet/connectors/uniswap/main.sol/ConnectV2UniswapV2.json"
const DAI_TOKEN_ADDR = tokens.dai.address // DAI Token
// PoolTogether Address: https://docs.pooltogether.com/resources/networks/ethereum
const DAI_PRIZE_POOL_ADDR = "0xEBfb47A7ad0FD6e57323C8A42B2E5A6a4F68fc1a" // DAI Prize Pool
const PT_DAI_TICKET_ADDR = "0x334cBb5858417Aee161B53Ee0D5349cCF54514CF" // PT DAI Ticket
const DAI_POOL_FAUCET_ADDR = "0xF362ce295F2A4eaE4348fFC8cDBCe8d729ccb8Eb" // DAI POOL Faucet
const POOL_TOKEN_ADDRESS = "0x0cEC1A9154Ff802e7934Fc916Ed7Ca50bDE6844e" // POOL Tocken
const TOKEN_FAUCET_PROXY_FACTORY_ADDR = "0xE4E9cDB3E139D7E8a41172C20b6Ed17b6750f117" // TokenFaucetProxyFactory for claimAll
const DAI_POD_ADDR = "0x2f994e2E4F3395649eeE8A89092e63Ca526dA829" // DAI Pod
const UNISWAP_POOLETHLP_PRIZE_POOL_ADDR = "0x3AF7072D29Adde20FC7e173a7CB9e45307d2FB0A" // Uniswap Pool/ETH LP PrizePool
const UNISWAP_POOLETHLP_FAUCET_ADDR = "0x9A29401EF1856b669f55Ae5b24505b3B6fAEb370" // Uniswap Pool/ETH LP Faucet
const UNISWAP_POOLETHLP_TOKEN_ADDR = "0x85cb0bab616fe88a89a35080516a8928f38b518b" // Uniswap Pool/ETH Token
const PT_UNISWAP_POOLETHLP_TICKET_ADDR = "0xeb8928ee92efb06c44d072a24c2bcb993b61e543" // Pool Together Uniswap Pool/ETH LP Ticket
const POOL_PRIZE_POOL_ADDR = "0x396b4489da692788e327e2e4b2b0459a5ef26791" // POOL Prize Pool
const PT_POOL_TICKET_ADDR = "0x27d22a7648e955e510a40bdb058333e9190d12d4" // Pool Together POOL Ticket
const WETH_ADDR = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" // WETH
const DAI_POD_TOKEN_DROP = "0xc5209623E3dFdf9C0cCbe497c8012883C4147731"
// Community WETH Prize Pool (Rari): https://reference-app.pooltogether.com/pools/mainnet/0xa88ca010b32a54d446fc38091ddbca55750cbfc3/manage#stats
const WETH_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3" // Community WETH Prize Pool (Rari)
const WETH_POOL_TICKET_ADDR = "0x9b5c30aeb9ce2a6a121cea9a85bc0d662f6d9b40" // Community WETH Prize Pool Ticket (Rari)
const prizePoolABI = [
"function calculateEarlyExitFee( address from, address controlledToken, uint256 amount) external returns ( uint256 exitFee, uint256 burnedCredit)"
]
const podABI = [
"function getEarlyExitFee(uint256 amount) external returns (uint256)",
"function balanceOfUnderlying(address user) external view returns (uint256 amount)",
"function drop() public returns (uint256)",
"function balanceOf(address account) external view returns (uint256)"
]
const POD_FACTORY_ADDRESS = "0x4e3a9f9fbafb2ec49727cffa2a411f7a0c1c4ce1"
const podFactoryABI = [
"function create( address _prizePool, address _ticket, address _faucet, address _manager, uint8 _decimals) external returns (address pod)"
]
const tokenDropABI = [
"function claim(address user) external returns (uint256)",
]
describe("PoolTogether", function () {
const connectorName = "COMPOUND-TEST-A"
const uniswapConnectorName = "UNISWAP-TEST-A"
const ptConnectorName = "POOLTOGETHER-TEST-A"
let dsaWallet0: any
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
let ptConnector: any;
let uniswapConnector: any;
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);
// Deploy and enable Compound Connector
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2CompoundArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
// Deploy and enable Pool Together Connector
ptConnector = await deployAndEnableConnector({
connectorName: ptConnectorName,
contractArtifact: connectV2PoolTogetherArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
// Deploy and enable Uniswap Connector
uniswapConnector = await deployAndEnableConnector({
connectorName: uniswapConnectorName,
contractArtifact: connectV2UniswapArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!ptConnector.address).to.be.true;
expect(!!uniswapConnector.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 10 ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main - DAI Prize Pool Test", function () {
it("Should deposit 1 ETH in Compound", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const spells = [
{
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 100 DAI from Compound and deposit DAI into DAI Prize Pool", async 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: ptConnectorName,
method: "depositTo",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, setId, 0]
}
]
// Before Spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance is 0`).to.be.eq(ethers.utils.parseEther("0"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether DAI Ticket balance is 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `Expect DAI balance to still equal 0 since it was deposited into Prize Pool`).to.be.eq(0);
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether DAI Ticket balance equals 100`).to.be.eq(ethers.utils.parseEther("100"));
// ETH used for transaction
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(ethers.utils.parseEther("9"));
});
it("Should wait 11 days, withdraw all PrizePool, get back 100 DAI, and claim POOL", async function () {
const amount = ethers.utils.parseEther("100") // 100 DAI
let prizePoolContract = new ethers.Contract(DAI_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 1 DAI because starts at 10%").to.be.eq(ethers.utils.parseEther("1"));
const spells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claim",
args: [DAI_POOL_FAUCET_ADDR, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance equals 0`).to.be.eq(ethers.utils.parseEther("0"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether Dai Ticket is 100`).to.be.eq(ethers.utils.parseEther("100"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token equals 0`).to.be.eq(ethers.utils.parseEther("0"));
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11 * 24 * 60 * 60]);
await ethers.provider.send("evm_mine");
earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 DAI because past 10 days").to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance to be equal to 100, because of no early withdrawal fee`
).to.be.eq(ethers.utils.parseEther("100"));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether Dai Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token Balance to be greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit and withdraw all PrizePool, get back less than 100 DAI", async function () {
const amount = ethers.utils.parseEther("100") // 100 DAI
const exitFee = ethers.utils.parseEther("1") // 1 DAI is 10% of 100 DAI
const spells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, 0, 0]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, exitFee, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI Balance equals 0`).to.be.eq(ethers.utils.parseEther("100"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether DAI Ticket equals 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `PoolTogether Token greater than 0`).to.be.gt(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance to be less than 100, because of early withdrawal fee`
).to.be.lt(ethers.utils.parseEther("100"));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether Dai Ticket to equal 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token Balance to greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
it("Should deposit, wait 11 days, and withdraw all PrizePool, get 99 DAI, and claim all POOL using claimAll", async function () {
const amount = ethers.utils.parseEther("99") // 99 DAI
const depositSpells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance less than 100`).to.be.lt(ethers.utils.parseEther("100"));
let cToken = await ethers.getContractAt(abis.basic.erc20, PT_DAI_TICKET_ADDR)
const balance = await cToken.balanceOf(dsaWallet0.address)
expect(balance, `PoolTogether DAI Ticket equal 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token is greater than 0`).to.be.gt(ethers.utils.parseEther("0"));
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpells), wallet1.address)
const receipt = await tx.wait()
const prizePoolContract = new ethers.Contract(DAI_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to .99 DAI because starts at 10%").to.be.eq(ethers.utils.parseEther(".99"));
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11 * 24 * 60 * 60]);
await ethers.provider.send("evm_mine");
earlyExitFee = await prizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_DAI_TICKET_ADDR, amount);
expect(earlyExitFee.exitFee, "Exit Fee equal to 0 DAI because past 10 days").to.be.eq(0);
const withdrawSpells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [DAI_PRIZE_POOL_ADDR, amount, PT_DAI_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claimAll",
args: [TOKEN_FAUCET_PROXY_FACTORY_ADDR, [DAI_POOL_FAUCET_ADDR]]
}
]
// Run spell transaction
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpells), wallet1.address)
const receipt2 = await tx2.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance equals 99`).to.be.eq(ethers.utils.parseEther("99"));
const balanceAfter = await cToken.balanceOf(dsaWallet0.address)
expect(balanceAfter, `PoolTogether DAI Ticket equal 0`).to.be.eq(0);
// Expect
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `Pool Token to be greateir than 0`).to.be.gt(ethers.utils.parseEther("0"));
});
})
describe("Main - DAI Pod Test", function () {
it("Should deposit 99 DAI in DAI Pod", async function () {
const amount = ethers.utils.parseEther("99") // 99 DAI
const spells = [
{
connector: ptConnectorName,
method: "depositToPod",
args: [DAI_TOKEN_ADDR, DAI_POD_ADDR, amount, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI balance equals 99`).to.be.eq(ethers.utils.parseEther("99"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR)
const podBalance = await podToken.balanceOf(dsaWallet0.address)
expect(podBalance, `Pod DAI Token equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI equals 0`).to.be.eq(0);
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token greater than 0`).to.be.gt(0);
const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address)
expect(podBalanceAfter, `Pod DAI token greater than 0`).to.be.eq(ethers.utils.parseEther("99"));
});
it("Should claim rewards from pod token drop", async function () {
const spells = [
{
connector: ptConnectorName,
method: "claimPodTokenDrop",
args: [DAI_POD_TOKEN_DROP, 0]
}
]
const tokenDropContract = new ethers.Contract(DAI_POD_TOKEN_DROP, tokenDropABI, ethers.provider);
const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, masterSigner);
// drop(): Claim TokenDrop asset for PrizePool Pod and transfers token(s) to external Pod TokenDrop
// dropt() also calls batch which, Deposit Pod float into PrizePool. Deposits the current float
// amount into the PrizePool and claims current POOL rewards.
const dropTx = await podContract.drop();
await dropTx.wait();
// POOL Rewards able to claim from Pod Token Drop
let claimAmount = await tokenDropContract.callStatic["claim"](dsaWallet0.address);
// Before spell
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
const total = claimAmount.add(poolBalance);
expect(poolBalanceAfter, `POOL Token same as before spell`).to.be.eq(total);
});
it("Should wait 11 days, withdraw all podTokens, get back 99 DAI", async function () {
const amount = ethers.utils.parseEther("99") // 99 DAI
const podContract = new ethers.Contract(DAI_POD_ADDR, podABI, ethers.provider);
let maxFee = await podContract.callStatic["getEarlyExitFee"](amount);
// maxFee depends on if token has been deposited to PrizePool yet
// since we called drop in previous test case, the tokens were deposited to PrizePool
expect(maxFee, "Exit Fee equal to .99 DAI because token still in float").to.be.eq(ethers.utils.parseEther(".99"));
const spells = [
{
connector: ptConnectorName,
method: "withdrawFromPod",
args: [DAI_POD_ADDR, amount, maxFee, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI Balance equals 0`).to.be.eq(0);
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token balance greater than 0`).to.be.gt(0);
let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR)
const podBalance = await podToken.balanceOf(dsaWallet0.address)
expect(podBalance, `Pod DAI Token equals 99`).to.be.eq(ethers.utils.parseEther("99"));
// Increase time by 11 days so we get back all DAI without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [11 * 24 * 60 * 60]);
await ethers.provider.send("evm_mine");
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance equals 99, because of no early withdrawal fee`
).to.be.eq(ethers.utils.parseEther("99"));
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token to be greater than 0`).to.be.gt(0);
const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address)
expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(0);
});
it("Should deposit and withdraw from pod, get back same amount of 99 DAI", async function () {
const amount = ethers.utils.parseEther("99")
const maxFee = 0; // maxFee 0 since it doesn't give chance for Pod to actually deposit into PrizePool
const spells = [
{
connector: ptConnectorName,
method: "depositToPod",
args: [DAI_TOKEN_ADDR, DAI_POD_ADDR, amount, 0, 0]
},
{
connector: ptConnectorName,
method: "withdrawFromPod",
args: [DAI_POD_ADDR, amount, maxFee, 0, 0]
}
]
// Before spell
let daiToken = await ethers.getContractAt(abis.basic.erc20, DAI_TOKEN_ADDR)
let daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance, `DAI equals 99`).to.be.eq(ethers.utils.parseEther("99"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
// PodToken is 0
let podToken = await ethers.getContractAt(abis.basic.erc20, DAI_POD_ADDR)
const podBalance = await podToken.balanceOf(dsaWallet0.address)
expect(podBalance, `Pod DAI Token equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
daiBalance = await daiToken.balanceOf(dsaWallet0.address);
expect(daiBalance,
`DAI balance to be equal to 99, because funds still in 'float`
).to.be.eq(ethers.utils.parseEther("99"));
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token same as before spell`).to.be.eq(poolBalance);
// Expect Pod Token Balance to equal 0
const podBalanceAfter = await podToken.balanceOf(dsaWallet0.address)
expect(podBalanceAfter, `Pod DAI Token equals 0`).to.be.eq(ethers.utils.parseEther("0"));
});
})
describe("Main - UNISWAP POOL/ETH Prize Pool Test", function () {
it("Should use uniswap to swap ETH for POOL, deposit to POOL/ETH LP, deposit POOL/ETH LP to PrizePool", async function () {
const amount = ethers.utils.parseEther("100") // 100 POOL
const slippage = ethers.utils.parseEther("0.03");
const setId = "83478237"
const UniswapV2Router02ABI = [
"function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)"
];
// Get amount of ETH for 100 POOL from Uniswap
const UniswapV2Router02 = await ethers.getContractAt(UniswapV2Router02ABI, "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D");
const amounts = await UniswapV2Router02.getAmountsOut(amount, [POOL_TOKEN_ADDRESS, WETH_ADDR]);
const unitAmount = ethers.utils.parseEther(((amounts[1] * 1.03) / amounts[0]).toString());
const spells = [
{
connector: uniswapConnectorName,
method: "buy",
args: [POOL_TOKEN_ADDRESS, tokens.eth.address, amount, unitAmount, 0, setId]
},
{
connector: uniswapConnectorName,
method: "deposit",
args: [POOL_TOKEN_ADDRESS, tokens.eth.address, amount, unitAmount, slippage, 0, setId]
},
{
connector: ptConnectorName,
method: "depositTo",
args: [UNISWAP_POOLETHLP_PRIZE_POOL_ADDR, 0, PT_UNISWAP_POOLETHLP_TICKET_ADDR, setId, 0]
}
]
// Before Spell
let ethBalance = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalance, `ETH Balance equals 9`).to.be.eq(ethers.utils.parseEther("9"));
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
let uniswapLPToken = await ethers.getContractAt(abis.basic.erc20, UNISWAP_POOLETHLP_TOKEN_ADDR)
const uniswapPoolEthBalance = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalance, `Uniswap POOL/ETH LP equals 0`).to.be.eq(0);
let ptUniswapPoolEthToken = await ethers.getContractAt(abis.basic.erc20, PT_UNISWAP_POOLETHLP_TICKET_ADDR)
const ptUniswapPoolEthBalance = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
expect(ptUniswapPoolEthBalance, `PoolTogether Uniswap POOL?ETH LP equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
ethBalance = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalance, `ETH Balance less than 9`).to.be.lt(ethers.utils.parseEther("9"));
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `POOL Token to be same after spell`).to.be.eq(poolBalance);
const uniswapPoolEthBalanceAfter = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalanceAfter, `Uniswap POOL/ETH LP equals 0`).to.be.eq(0);
const ptUniswapPoolEthBalanceAfter = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
expect(ptUniswapPoolEthBalanceAfter, `PT Uniswap POOL/ETH LP to greater than 0`).to.be.gt(0);
});
it("Should withdraw all PrizePool, get back Uniswap LP, claim POOL, deposit claimed POOL into Pool PrizePool", async function () {
let ptUniswapPoolEthToken = await ethers.getContractAt(abis.basic.erc20, PT_UNISWAP_POOLETHLP_TICKET_ADDR)
const ptUniswapPoolEthBalance = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
const setId = "83478237"
let uniswapPrizePoolContract = new ethers.Contract(UNISWAP_POOLETHLP_PRIZE_POOL_ADDR, prizePoolABI, ethers.provider);
let earlyExitFee = await uniswapPrizePoolContract.callStatic["calculateEarlyExitFee"](dsaWallet0.address, PT_UNISWAP_POOLETHLP_TICKET_ADDR, ptUniswapPoolEthBalance);
expect(earlyExitFee.exitFee, "Exit Fee equals 0 because no early exit fee for this prize pool").to.be.eq(0);
const spells = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [UNISWAP_POOLETHLP_PRIZE_POOL_ADDR, ptUniswapPoolEthBalance, PT_UNISWAP_POOLETHLP_TICKET_ADDR, earlyExitFee.exitFee, 0, 0]
},
{
connector: ptConnectorName,
method: "claim",
args: [UNISWAP_POOLETHLP_FAUCET_ADDR, setId]
},
{
connector: ptConnectorName,
method: "depositTo",
args: [POOL_PRIZE_POOL_ADDR, 0, PT_POOL_TICKET_ADDR, setId, 0]
}
]
// Before spell
let poolToken = await ethers.getContractAt(abis.basic.erc20, POOL_TOKEN_ADDRESS)
const poolBalance = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalance, `POOL Token greater than 0`).to.be.gt(0);
// Uniswap POOL/ETH LP is 0
let uniswapLPToken = await ethers.getContractAt(abis.basic.erc20, UNISWAP_POOLETHLP_TOKEN_ADDR)
const uniswapPoolEthBalance = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalance, `Uniswap POOL/ETH LP equals 0`).to.be.eq(0);
expect(ptUniswapPoolEthBalance, `PT Uniswap POOL/ETH LP greater than 0`).to.be.gt(0);
let poolPoolTicket = await ethers.getContractAt(abis.basic.erc20, PT_POOL_TICKET_ADDR)
const poolPoolTicketBalance = await poolPoolTicket.balanceOf(dsaWallet0.address)
expect(poolPoolTicketBalance, `PoolTogether POOL Ticket equals 0`).to.be.eq(0);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
const poolBalanceAfter = await poolToken.balanceOf(dsaWallet0.address)
expect(poolBalanceAfter, `Pool Token Balance equal to balance before spell`).to.be.eq(poolBalance);
const uniswapPoolEthBalanceAfter = await uniswapLPToken.balanceOf(dsaWallet0.address)
expect(uniswapPoolEthBalanceAfter, `Uniswap POOL/ETH LP to greater than 0`).to.be.gt(0);
const ptUniswapPoolEthBalanceAfter = await ptUniswapPoolEthToken.balanceOf(dsaWallet0.address)
expect(ptUniswapPoolEthBalanceAfter, `PT Uniswap POOL/ETH LP equal 0`).to.be.eq(0);
const poolPoolTicketBalanceAfter = await poolPoolTicket.balanceOf(dsaWallet0.address)
expect(poolPoolTicketBalanceAfter, `PoolTogether POOL Ticket greater than 0`).to.be.gt(0);
});
})
describe("Main - WETH Prize Pool Test", function () {
it("Deposit 1 ETH into WETH Prize Pool and withdraw immediately", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const setId = "83478237"
const spells = [
{
connector: ptConnectorName,
method: "depositTo",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, setId]
},
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, setId, 0]
},
]
// Before Spell
const ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After spell
const ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
// ETH used for transaction
expect(ethBalanceAfter, `ETH Balance less than before spell because of early withdrawal fee`).to.be.lte(ethBalanceBefore);
});
it("Deposit 1 ETH into WETH Prize Pool, wait 14 days, then withdraw", async function () {
const amount = ethers.utils.parseEther("1") // 1 ETH
const depositSpell = [
{
connector: ptConnectorName,
method: "depositTo",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, 0, 0]
}
]
const withdrawSpell = [
{
connector: ptConnectorName,
method: "withdrawInstantlyFrom",
args: [WETH_PRIZE_POOL_ADDR, amount, WETH_POOL_TICKET_ADDR, amount, 0, 0]
}
]
// Before Deposit Spell
let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run deposit spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(depositSpell), wallet1.address)
const receipt = await tx.wait()
// After Deposit spell
let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH Balance less than before spell`).to.be.lte(ethBalanceBefore);
// Increase time by 11 days so we get back all ETH without early withdrawal fee
await ethers.provider.send("evm_increaseTime", [14 * 24 * 60 * 60]);
await ethers.provider.send("evm_mine");
// Run withdraw spell transaction
const tx2 = await dsaWallet0.connect(wallet0).cast(...encodeSpells(withdrawSpell), wallet1.address)
const receipt2 = await tx.wait()
// After Deposit spell
ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH Balance equal to before spell because no early exit fee`).to.be.eq(ethBalanceBefore);
});
});
describe("Main - WETH Pod Test", function () {
let podAddress
it("Should deposit 1 ETH in WETH Pod and get Pod Ticket", async function () {
const amount = ethers.utils.parseEther("1")
// Create Pod for WETH Prize Pool (Rari)
const podFactoryContract = new ethers.Contract(POD_FACTORY_ADDRESS, podFactoryABI, masterSigner)
podAddress = await podFactoryContract.callStatic.create(WETH_PRIZE_POOL_ADDR, WETH_POOL_TICKET_ADDR, constants.address_zero, wallet0.address, 18)
await podFactoryContract.create(WETH_PRIZE_POOL_ADDR, WETH_POOL_TICKET_ADDR, constants.address_zero, wallet0.address, 18)
const spells = [
{
connector: ptConnectorName,
method: "depositToPod",
args: [WETH_ADDR, podAddress, amount, 0, 0]
}
]
// Before Deposit Spell
const podContract = new ethers.Contract(podAddress, podABI, ethers.provider);
let podBalanceBefore = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceBefore, `Pod balance equal to 0`).to.be.eq(0);
let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After Deposit spell
let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH balance less than before`).to.be.lt(ethBalanceBefore);
podBalanceAfter = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceAfter, `Pod balance equal to 1`).to.be.eq(ethers.utils.parseEther("1"));
});
it("Should withdraw 1 Ticket from WETH Pod and get back ETH", async function () {
const amount = ethers.utils.parseEther("1")
const podContract = new ethers.Contract(podAddress, podABI, ethers.provider);
let maxFee = await podContract.callStatic["getEarlyExitFee"](amount);
expect(maxFee, "Exit Fee equal to 0 DAI because token still in float").to.be.eq(0);
// maxFee depends on if token has been deposited to PrizePool yet
const spells = [
{
connector: ptConnectorName,
method: "withdrawFromPod",
args: [podAddress, amount, maxFee, 0, 0]
}
]
// Before Deposit Spell
let podBalanceBefore = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceBefore, `Pod balance equal to 1`).to.be.eq(ethers.utils.parseEther("1"));
let ethBalanceBefore = await ethers.provider.getBalance(dsaWallet0.address);
// Run spell transaction
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address)
const receipt = await tx.wait()
// After Deposit spell
let ethBalanceAfter = await ethers.provider.getBalance(dsaWallet0.address);
expect(ethBalanceAfter, `ETH balance greater than before`).to.be.gt(ethBalanceBefore);
podBalanceAfter = await podContract.balanceOfUnderlying(dsaWallet0.address)
expect(podBalanceAfter, `Pod balance equal to 0`).to.be.eq(ethers.utils.parseEther("0"));
});
});
})

View File

@ -1,12 +1,12 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle;
const { provider, deployContract } = waffle
const USDC_ADDR = "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8";
const WETH_ADDR = "0x82af49447d8a07e3bd95bd0d56f35241523fbab1";
describe("Uniswap-sell-beta", function() {
describe("Uniswap-sell-beta", function () {
let UniswapSellBeta, uniswapSellBeta;
async function setBalance(address) {
@ -64,7 +64,7 @@ describe("Uniswap-sell-beta", function() {
await uniswapSellBeta.deployed();
});
it("Should have contracts deployed.", async function() {
it("Should have contracts deployed.", async function () {
expect(uniswapSellBeta.address).to.exist;
});

View File

@ -1,26 +1,27 @@
const { expect } = require("chai");
const hre = require("hardhat");
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle;
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js");
const buildDSAv2 = require("../../../scripts/buildDSAv2");
const encodeSpells = require("../../../scripts/encodeSpells.js");
const encodeFlashcastData = require("../../../scripts/encodeFlashcastData.js");
const getMasterSigner = require("../../../scripts/getMasterSigner");
const addLiquidity = require("../../../scripts/addLiquidity");
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js";
import { buildDSAv2 } from "../../../scripts/buildDSAv2";
import { encodeSpells } from "../../../scripts/encodeSpells.js";
import { encodeFlashcastData } from "../../../scripts/encodeFlashcastData.js";
import { getMasterSigner } from "../../../scripts/getMasterSigner";
import { addLiquidity } from "../../../scripts/addLiquidity";
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const constants = require("../../../scripts/constant/constant");
const tokens = require("../../../scripts/constant/tokens");
const {
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 {
abi: nftManagerAbi,
} = require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json");
} from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json";
const connectV2UniswapV3Artifacts = require("../../artifacts/contracts/mainnet/connectors/uniswap/v3/main.sol/ConnectV2UniswapV3.json");
const { eth } = require("../../../scripts/constant/tokens");
const { BigNumber } = require("ethers");
import connectV2UniswapV3Artifacts from "../../artifacts/contracts/mainnet/connectors/uniswap/v3/main.sol/ConnectV2UniswapV3.json"
import { eth } from "../../../scripts/constant/tokens"
import { BigNumber } from "ethers"
const FeeAmount = {
LOW: 500,
@ -41,7 +42,7 @@ let tokenIds = [];
let liquidities = [];
const abiCoder = ethers.utils.defaultAbiCoder;
describe("UniswapV3", function() {
describe("UniswapV3", function () {
const connectorName = "UniswapV3-v1";
let dsaWallet0;
@ -82,19 +83,19 @@ describe("UniswapV3", function() {
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(!!connector.address).to.be.true;
expect(!!masterSigner.address).to.be.true;
});
describe("DSA wallet setup", function() {
it("Should build DSA v2", async function() {
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 & DAI into DSA wallet", async function() {
it("Deposit ETH & DAI into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10"),
@ -110,7 +111,7 @@ describe("UniswapV3", function() {
);
});
it("Deposit ETH & USDT into DSA wallet", async function() {
it("Deposit ETH & USDT into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10"),
@ -127,8 +128,8 @@ describe("UniswapV3", function() {
});
});
describe("Main", function() {
it("Should mint successfully", async function() {
describe("Main", function () {
it("Should mint successfully", async function () {
const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH
const daiAmount = ethers.utils.parseEther("400"); // 1 ETH
const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12); // 1 ETH
@ -236,7 +237,7 @@ describe("UniswapV3", function() {
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 ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH
const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12); // 1 ETH
@ -302,7 +303,7 @@ describe("UniswapV3", function() {
expect(data.liquidity).to.be.equals(liquidities[0]);
});
it("Should withdraw successfully", async function() {
it("Should withdraw successfully", async function () {
const getId = "0";
const setIds = ["0", "0"];
@ -331,7 +332,7 @@ describe("UniswapV3", function() {
expect(data1.liquidity.toNumber()).to.be.equals(0);
});
it("Should collect successfully", async function() {
it("Should collect successfully", async function () {
const ethAmount = ethers.utils.parseEther("0.2"); // 1 ETH
const daiAmount = ethers.utils.parseEther("800"); // 1 ETH
const getIds = ["0", "0"];
@ -351,7 +352,7 @@ describe("UniswapV3", function() {
const receipt = await tx.wait();
});
it("Should burn successfully", async function() {
it("Should burn successfully", async function () {
const spells = [
{
connector: connectorName,

View File

@ -1,20 +1,20 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { waffle, ethers } = hre;
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
const addLiquidity = require("../../../scripts/addLiquidity");
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js";
import { buildDSAv2 } from "../../../scripts/buildDSAv2";
import { encodeSpells } from "../../../scripts/encodeSpells.js";
import { getMasterSigner } from "../../../scripts/getMasterSigner";
import { addLiquidity } from "../../../scripts/addLiquidity";
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const { abi: nftManagerAbi } = require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json")
import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { abi: nftManagerAbi } from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json"
const connectV2UniswapStakerArtifacts = require("../../artifacts/contracts/mainnet/connectors/uniswap/v3_staker/main.sol/ConnectV2UniswapV3Staker.json");
const connectV2UniswapV3Artifacts = require("../../artifacts/contracts/mainnet/connectors/uniswap/v3/main.sol/ConnectV2UniswapV3.json");
import connectV2UniswapStakerArtifacts from "../../artifacts/contracts/mainnet/connectors/uniswap/v3_staker/main.sol/ConnectV2UniswapV3Staker.json";
import connectV2UniswapV3Artifacts from "../../artifacts/contracts/mainnet/connectors/uniswap/v3/main.sol/ConnectV2UniswapV3.json";
const FeeAmount = {
LOW: 500,
@ -39,11 +39,11 @@ describe("UniswapV3", function () {
const connectorStaker = "UniswapStaker-v1"
const connectorUniswap = "UniswapV3-v1"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
let startTime, endTime;
let dsaWallet0: any
let masterSigner: any;
let instaConnectorsV2: any;
let connector: any;
let startTime: any, endTime: any;
const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets
@ -61,7 +61,7 @@ describe("UniswapV3", function () {
});
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88");
let nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88");
connector = await deployAndEnableConnector({
connectorName: connectorStaker,
contractArtifact: connectV2UniswapStakerArtifacts,
@ -70,7 +70,7 @@ describe("UniswapV3", function () {
})
console.log("Connector address", connector.address)
uniswapConnector = await deployAndEnableConnector({
let uniswapConnector = await deployAndEnableConnector({
connectorName: connectorUniswap,
contractArtifact: connectV2UniswapV3Artifacts,
signer: masterSigner,
@ -214,8 +214,8 @@ describe("UniswapV3", function () {
let castEvent = new Promise((resolve, reject) => {
dsaWallet0.on('LogCast', (origin, sender, value, targetNames, targets, eventNames, eventParams, event) => {
const params = abiCoder.decode(["bytes32","address","address","uint256","uint256","uint256"], eventParams[0]);
const params1 = abiCoder.decode(["bytes32","address","address","uint256","uint256","uint256"], eventParams[1]);
const params = abiCoder.decode(["bytes32", "address", "address", "uint256", "uint256", "uint256"], eventParams[0]);
const params1 = abiCoder.decode(["bytes32", "address", "address", "uint256", "uint256", "uint256"], eventParams[1]);
event.removeListener();
resolve({ start: [params[3], params1[3]], end: [params[4], params1[4]] });
@ -287,6 +287,8 @@ describe("UniswapV3", function () {
ethAddress,
"1000",
],
},
{
connector: connectorStaker,
method: "claimRewards",
args: [

View File

@ -1,153 +0,0 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { waffle, ethers } = hre;
const { provider } = waffle
const deployAndEnableConnector = require("../../../scripts/deployAndEnableConnector.js")
const buildDSAv2 = require("../../../scripts/buildDSAv2")
const encodeSpells = require("../../../scripts/encodeSpells.js")
const getMasterSigner = require("../../../scripts/getMasterSigner")
const tokens = require("../../../scripts/constant/tokens");
const addresses = require("../../../scripts/constant/addresses");
const abis = require("../../../scripts/constant/abis");
const connectV2YearnArtifacts = require("../../artifacts/contracts/mainnet/connectors/yearn_v2/main.sol/ConnectV2YearnV2.json")
const toBytes32 = (bn) => {
return ethers.utils.hexlify(ethers.utils.zeroPad(bn.toHexString(), 32));
};
const setStorageAt = async (address, index, value) => {
await ethers.provider.send("hardhat_setStorageAt", [address, index, value]);
await ethers.provider.send("evm_mine", []); // Just mines to the next block
};
describe("Yearn", function () {
const connectorName = "YEARN-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
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: 12996975,
},
},
],
});
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2YearnArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
console.log("Connector address", connector.address)
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!masterSigner.address).to.be.true;
});
describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.address)
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () {
it("Should increase the DAI balance to 100 DAI", async function () {
const DAI = new ethers.Contract(tokens.dai.address, abis.basic.erc20, ethers.provider);
const DAI_SLOT = 2;
const locallyManipulatedBalance = ethers.utils.parseEther("100");
// Get storage slot index
const index = ethers.utils.solidityKeccak256(
["uint256", "uint256"],
[dsaWallet0.address, DAI_SLOT]
);
// Manipulate local balance (needs to be bytes32 string)
await setStorageAt(
tokens.dai.address,
index.toString(),
toBytes32(locallyManipulatedBalance).toString()
);
// Get DAI balance
const balance = await DAI.balanceOf(dsaWallet0.address);
expect(await ethers.BigNumber.from(balance).eq(ethers.utils.parseEther("100")));
});
it("Should deposit and withdraw 50 DAI in/out the Yearn Vault", async function () {
const DAI = new ethers.Contract(tokens.dai.address, abis.basic.erc20, ethers.provider);
const DAI_VAULT = '0xdA816459F1AB5631232FE5e97a05BBBb94970c95';
const amount = ethers.utils.parseEther("50") // 50 DAI
const setId = "132456";
const spells = [
{
connector: connectorName,
method: "deposit",
args: [DAI_VAULT, amount, 0, setId]
},
{
connector: connectorName,
method: "withdraw",
args: [DAI_VAULT, amount, setId, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
await tx.wait();
// Get DAI balance
const balance = await DAI.balanceOf(dsaWallet0.address);
expect(await ethers.BigNumber.from(balance).eq(ethers.utils.parseEther("100")));
});
it("Should deposit 70 DAI in the Yearn Vault", async function () {
const DAI_VAULT = '0xdA816459F1AB5631232FE5e97a05BBBb94970c95';
const DAI = new ethers.Contract(tokens.dai.address, abis.basic.erc20, ethers.provider);
const YVDAI = new ethers.Contract(DAI_VAULT, abis.basic.erc20, ethers.provider);
const amount = ethers.utils.parseEther("70") // 70 DAI
const setId = "568445";
const spells = [
{
connector: connectorName,
method: "deposit",
args: [DAI_VAULT, amount, 0, setId]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
await tx.wait();
// Get DAI balance
const yvDAIBalance = await YVDAI.balanceOf(dsaWallet0.address);
const daiBalance = await DAI.balanceOf(dsaWallet0.address);
const correctDaiBalance = await ethers.BigNumber.from(daiBalance).eq(ethers.utils.parseEther("30"));
const correctYVDaiBalance = await ethers.BigNumber.from(yvDAIBalance).lte(ethers.utils.parseEther("70"));
expect(correctDaiBalance && correctYVDaiBalance);
});
})
})

View File

@ -0,0 +1,154 @@
import { expect } from "chai";
import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/deployAndEnableConnector.js"
import { buildDSAv2 } from "../../../scripts/buildDSAv2"
import { encodeSpells } from "../../../scripts/encodeSpells.js"
import { getMasterSigner } from "../../../scripts/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { tokens } from "../../../scripts/constant/tokens";
import connectV2YearnArtifacts from "../../artifacts/contracts/mainnet/connectors/yearn_v2/main.sol/ConnectV2YearnV2.json"
const toBytes32 = (bn) => {
return ethers.utils.hexlify(ethers.utils.zeroPad(bn.toHexString(), 32));
};
const setStorageAt = async (address, index, value) => {
await ethers.provider.send("hardhat_setStorageAt", [address, index, value]);
await ethers.provider.send("evm_mine", []); // Just mines to the next block
};
describe("Yearn", function () {
const connectorName = "YEARN-TEST-A"
let dsaWallet0
let masterSigner;
let instaConnectorsV2;
let connector;
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: 12996975,
},
},
],
});
masterSigner = await getMasterSigner(wallet3)
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: connectV2YearnArtifacts,
signer: masterSigner,
connectors: instaConnectorsV2
})
console.log("Connector address", connector.address)
})
it("Should have contracts deployed.", async function () {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!masterSigner.address).to.be.true;
});
describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.address)
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit ETH into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: ethers.utils.parseEther("10")
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("10"));
});
});
describe("Main", function () {
it("Should increase the DAI balance to 100 DAI", async function () {
const DAI = new ethers.Contract(tokens.dai.address, abis.basic.erc20, ethers.provider);
const DAI_SLOT = 2;
const locallyManipulatedBalance = ethers.utils.parseEther("100");
// Get storage slot index
const index = ethers.utils.solidityKeccak256(
["uint256", "uint256"],
[dsaWallet0.address, DAI_SLOT]
);
// Manipulate local balance (needs to be bytes32 string)
await setStorageAt(
tokens.dai.address,
index.toString(),
toBytes32(locallyManipulatedBalance).toString()
);
// Get DAI balance
const balance = await DAI.balanceOf(dsaWallet0.address);
expect(await ethers.BigNumber.from(balance).eq(ethers.utils.parseEther("100")));
});
it("Should deposit and withdraw 50 DAI in/out the Yearn Vault", async function () {
const DAI = new ethers.Contract(tokens.dai.address, abis.basic.erc20, ethers.provider);
const DAI_VAULT = '0xdA816459F1AB5631232FE5e97a05BBBb94970c95';
const amount = ethers.utils.parseEther("50") // 50 DAI
const setId = "132456";
const spells = [
{
connector: connectorName,
method: "deposit",
args: [DAI_VAULT, amount, 0, setId]
},
{
connector: connectorName,
method: "withdraw",
args: [DAI_VAULT, amount, setId, 0]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
await tx.wait();
// Get DAI balance
const balance = await DAI.balanceOf(dsaWallet0.address);
expect(await ethers.BigNumber.from(balance).eq(ethers.utils.parseEther("100")));
});
it("Should deposit 70 DAI in the Yearn Vault", async function () {
const DAI_VAULT = '0xdA816459F1AB5631232FE5e97a05BBBb94970c95';
const DAI = new ethers.Contract(tokens.dai.address, abis.basic.erc20, ethers.provider);
const YVDAI = new ethers.Contract(DAI_VAULT, abis.basic.erc20, ethers.provider);
const amount = ethers.utils.parseEther("70") // 70 DAI
const setId = "568445";
const spells = [
{
connector: connectorName,
method: "deposit",
args: [DAI_VAULT, amount, 0, setId]
}
]
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet0.address);
await tx.wait();
// Get DAI balance
const yvDAIBalance = await YVDAI.balanceOf(dsaWallet0.address);
const daiBalance = await DAI.balanceOf(dsaWallet0.address);
const correctDaiBalance = await ethers.BigNumber.from(daiBalance).eq(ethers.utils.parseEther("30"));
const correctYVDaiBalance = await ethers.BigNumber.from(yvDAIBalance).lte(ethers.utils.parseEther("70"));
expect(correctDaiBalance && correctYVDaiBalance);
});
})
})

View File

@ -5343,19 +5343,6 @@
"resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
"version" "1.0.0"
"fsevents@^1.2.7", "fsevents@~2.1.1":
"integrity" "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw=="
"resolved" "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz"
"version" "1.2.13"
dependencies:
"bindings" "^1.5.0"
"nan" "^2.12.1"
"fsevents@~2.3.2":
"integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="
"resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
"version" "2.3.2"
"function-bind@^1.1.1", "function-bind@~1.1.1":
"integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
"resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
@ -7730,16 +7717,16 @@
"fmix" "^0.1.0"
"imul" "^1.0.0"
"nan@^2.12.1", "nan@2.13.2":
"integrity" "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw=="
"resolved" "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz"
"version" "2.13.2"
"nan@^2.14.0":
"integrity" "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ=="
"resolved" "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz"
"version" "2.14.2"
"nan@2.13.2":
"integrity" "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw=="
"resolved" "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz"
"version" "2.13.2"
"nano-base32@^1.0.1":
"integrity" "sha1-ulSMh578+5DaHE2eCX20pGySVe8="
"resolved" "https://registry.npmjs.org/nano-base32/-/nano-base32-1.0.1.tgz"