updated test cases + scripts + fixes

This commit is contained in:
pradyuman-verma 2021-12-06 05:44:38 +05:30 committed by Ishan Jain
parent 5c275f3ad8
commit 2d594b0ad7
16 changed files with 2015 additions and 1404 deletions

19
package-lock.json generated
View File

@ -30,6 +30,7 @@
"@studydefi/money-legos": "^2.4.2", "@studydefi/money-legos": "^2.4.2",
"@tenderly/hardhat-tenderly": "^1.0.13", "@tenderly/hardhat-tenderly": "^1.0.13",
"@types/chai": "^4.2.22", "@types/chai": "^4.2.22",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "^16.11.11", "@types/node": "^16.11.11",
"chai": "^4.3.4", "chai": "^4.3.4",
@ -4138,6 +4139,15 @@
"integrity": "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==", "integrity": "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==",
"dev": true "dev": true
}, },
"node_modules/@types/chai-as-promised": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.4.tgz",
"integrity": "sha512-1y3L1cHePcIm5vXkh1DSGf/zQq5n5xDKG1fpCvf18+uOkpce0Z1ozNFPkyWsVswK7ntN1sZBw3oU6gmN+pDUcA==",
"dev": true,
"dependencies": {
"@types/chai": "*"
}
},
"node_modules/@types/glob": { "node_modules/@types/glob": {
"version": "7.2.0", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz",
@ -33045,6 +33055,15 @@
"integrity": "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==", "integrity": "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==",
"dev": true "dev": true
}, },
"@types/chai-as-promised": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.4.tgz",
"integrity": "sha512-1y3L1cHePcIm5vXkh1DSGf/zQq5n5xDKG1fpCvf18+uOkpce0Z1ozNFPkyWsVswK7ntN1sZBw3oU6gmN+pDUcA==",
"dev": true,
"requires": {
"@types/chai": "*"
}
},
"@types/glob": { "@types/glob": {
"version": "7.2.0", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz",

View File

@ -42,6 +42,7 @@
"@studydefi/money-legos": "^2.4.2", "@studydefi/money-legos": "^2.4.2",
"@tenderly/hardhat-tenderly": "^1.0.13", "@tenderly/hardhat-tenderly": "^1.0.13",
"@types/chai": "^4.2.22", "@types/chai": "^4.2.22",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "^16.11.11", "@types/node": "^16.11.11",
"chai": "^4.3.4", "chai": "^4.3.4",

View File

@ -3,9 +3,9 @@ import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; //check const { web3, deployments, waffle, ethers } = hre; //check
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses"; import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis"; import { abis } from "../../../scripts/constant/abis";

View File

@ -3,9 +3,9 @@ import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; //check const { web3, deployments, waffle, ethers } = hre; //check
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses"; import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis"; import { abis } from "../../../scripts/constant/abis";

View File

@ -3,9 +3,9 @@ import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses"; import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis"; import { abis } from "../../../scripts/constant/abis";

View File

@ -4,9 +4,9 @@ const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json" import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json"
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses" import { addresses } from "../../../scripts/constant/addresses"
import { abis } from "../../../scripts/constant/abis" import { abis } from "../../../scripts/constant/abis"

View File

@ -4,9 +4,9 @@ const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json" import { abi } from "../../../scripts/constant/abi/core/InstaImplementations.json"
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses" import { addresses } from "../../../scripts/constant/addresses"
import { abis } from "../../../scripts/constant/abis" import { abis } from "../../../scripts/constant/abis"

View File

@ -3,10 +3,10 @@ import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells"
import encodeFlashcastData from "../../../scripts/tests/encodeFlashcastData.js" import encodeFlashcastData from "../../../scripts/tests/encodeFlashcastData"
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
import { addresses } from "../../../scripts/constant/addresses"; import { addresses } from "../../../scripts/constant/addresses";

View File

@ -1,14 +1,15 @@
import { ethers, network } from "hardhat"; import hre, { ethers, network } from "hardhat";
import chai from "chai"; import chai from "chai";
import chaiPromise from "chai-as-promised"; import chaiPromise from "chai-as-promised";
import { solidity } from "ethereum-waffle"; import { solidity } from "ethereum-waffle";
import type { Signer, Contract } from "ethers";
chai.use(chaiPromise); chai.use(chaiPromise);
chai.use(solidity); chai.use(solidity);
const { expect } = chai; const { expect } = chai;
const getMapping = (address, signer) => { const getMapping = (address: string, signer: Signer) => {
return ethers.getContractAt("InstaMappingController", address, signer); return ethers.getContractAt("InstaMappingController", address, signer);
}; };
@ -25,6 +26,7 @@ describe("Test InstaMapping contract", () => {
params: [ params: [
{ {
forking: { forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url, jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 12796965, blockNumber: 12796965,
}, },

View File

@ -1,422 +1,561 @@
import { expect } from "chai"; import { expect } from "chai";
import hre from "hardhat"; import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle;
const ALCHEMY_ID = process.env.ALCHEMY_ID; const ALCHEMY_ID = process.env.ALCHEMY_ID;
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js" import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2" import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js" import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner" import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis";
import { tokens } from "../../../scripts/constant/tokens";
import type { Signer, Contract } from "ethers";
import { addresses } from "../../../scripts/constant/addresses" import { ConnectV2AaveV2Polygon__factory, ConnectV2PoolTogetherPolygon__factory } from "../../../typechain";
import { abis } from "../../../scripts/constant/abis"
import { constants } from "../../../scripts/constant/constant"
import { tokens } from "../../../scripts/constant/tokens"
const DAI_TOKEN_ADDR = tokens.dai.address; // DAI Token
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 // PoolTogether Address: https://docs.pooltogether.com/resources/networks/matic
const USDC_PRIZE_POOL_ADDR = "0xEE06AbE9e2Af61cabcb13170e01266Af2DEFa946" // USDC Prize Pool const USDC_PRIZE_POOL_ADDR = "0xEE06AbE9e2Af61cabcb13170e01266Af2DEFa946"; // USDC Prize Pool
const PT_USDC_TICKET_ADDR = "0x473E484c722EF9ec6f63B509b07Bb9cfB258820b" // PT USDC Ticket const PT_USDC_TICKET_ADDR = "0x473E484c722EF9ec6f63B509b07Bb9cfB258820b"; // PT USDC Ticket
const PT_USDC_SPONGSOR_TICKET_ADDR = "0x19c0e557ee5a9b456f613ba3d025a4dc45b52c35" // PT USDC Sponsor Ticket const PT_USDC_SPONGSOR_TICKET_ADDR =
const USDC_POOL_FAUCET_ADDR = "0x6cbc003fE015D753180f072d904bA841b2415498" // USDC POOL Faucet "0x19c0e557ee5a9b456f613ba3d025a4dc45b52c35"; // PT USDC Sponsor Ticket
const POOL_TOKEN_ADDRESS = "0x25788a1a171ec66Da6502f9975a15B609fF54CF6" // POOL Tocken const USDC_POOL_FAUCET_ADDR = "0x6cbc003fE015D753180f072d904bA841b2415498"; // USDC POOL Faucet
const TOKEN_FAUCET_PROXY_FACTORY_ADDR = "0xeaa636304a7C8853324B6b603dCdE55F92dfbab1" // TokenFaucetProxyFactory for claimAll 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 // 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_PRIZE_POOL_ADDR = "0xa88ca010b32a54d446fc38091ddbca55750cbfc3"; // Community WETH Prize Pool (Rari)
const WETH_POOL_TICKET_ADDR = "0x9b5c30aeb9ce2a6a121cea9a85bc0d662f6d9b40" // Community WETH Prize Pool Ticket (Rari) const WETH_POOL_TICKET_ADDR = "0x9b5c30aeb9ce2a6a121cea9a85bc0d662f6d9b40"; // Community WETH Prize Pool Ticket (Rari)
const prizePoolABI = [ const prizePoolABI = [
"function calculateEarlyExitFee( address from, address controlledToken, uint256 amount) external returns ( uint256 exitFee, uint256 burnedCredit)", "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)" "function creditPlanOf( address controlledToken) external view returns ( uint128 creditLimitMantissa, uint128 creditRateMantissa)",
] ];
const connectorsABI = [ const connectorsABI = [
"function isConnectors(string[] calldata connectorNames) external view returns (bool, address[] memory)" "function isConnectors(string[] calldata connectorNames) external view returns (bool, address[] memory)",
] ];
describe("PoolTogether", function () { describe("PoolTogether", function() {
const connectorName = "AAVEV2-TEST-A" const connectorName = "AAVEV2-TEST-A";
const ptConnectorName = "POOLTOGETHER-TEST-A" const ptConnectorName = "POOLTOGETHER-TEST-A";
let dsaWallet0 let dsaWallet0: any;
let masterSigner; let masterSigner: Signer;
let instaConnectorsV2; let instaConnectorsV2: Contract;
let connector; let connector: any;
let ptConnector; let ptConnector: Contract;
const wallets = provider.getWallets() const wallets = provider.getWallets();
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets;
before(async () => { before(async () => {
await hre.network.provider.request({ await hre.network.provider.request({
method: "hardhat_reset", method: "hardhat_reset",
params: [ params: [
{ {
forking: { forking: {
jsonRpcUrl: `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`, jsonRpcUrl: `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`,
blockNumber: 18717337, 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 () { masterSigner = await getMasterSigner();
it("Should build DSA v2", async function () { instaConnectorsV2 = await ethers.getContractAt(
dsaWallet0 = await buildDSAv2(wallet0.address) abis.core.connectorsV2,
expect(!!dsaWallet0.address).to.be.true; addresses.core.connectorsV2
}); );
it("Deposit 1000 MATIC into DSA wallet", async function () { // Deploy and enable Compound Connector
await wallet0.sendTransaction({ connector = await deployAndEnableConnector({
to: dsaWallet0.address, connectorName,
value: ethers.utils.parseEther("1000") contractArtifact: ConnectV2AaveV2Polygon__factory,
}); signer: masterSigner,
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("1000")); connectors: instaConnectorsV2,
});
}); });
describe("Main - USDC Prize Pool Test", function () { // Deploy and enable Pool Together Connector
ptConnector = await deployAndEnableConnector({
it("Should deposit 100 MATIC in AAVE V2", async function () { connectorName: ptConnectorName,
const amount = ethers.utils.parseEther("100") // 100 MATIC contractArtifact: ConnectV2PoolTogetherPolygon__factory,
const spells = [ signer: masterSigner,
{ connectors: instaConnectorsV2,
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);
// });
}); });
}) });
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(!!(await masterSigner.getAddress())).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.eth.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]);
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]);
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);
// });
});
});

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,23 @@
import { BigNumberish } from "@ethersproject/bignumber";
import { Contract } from "@ethersproject/contracts";
import { expect } from "chai"; import { expect } from "chai";
import hre from "hardhat"; import hre, { artifacts } from "hardhat";
const { web3, deployments, waffle, ethers } = hre; const { ethers } = hre;
const { provider, deployContract } = waffle
const USDC_ADDR = "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8"; const USDC_ADDR = "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8";
const WETH_ADDR = "0x82af49447d8a07e3bd95bd0d56f35241523fbab1"; const WETH_ADDR = "0x82af49447d8a07e3bd95bd0d56f35241523fbab1";
describe("Uniswap-sell-beta", function () { describe("Uniswap-sell-beta", function () {
let UniswapSellBeta, uniswapSellBeta; let UniswapSellBeta, uniswapSellBeta: Contract;
async function setBalance(address) { async function setBalance(address: any) {
await network.provider.send("hardhat_setBalance", [ await hre.network.provider.send("hardhat_setBalance", [
address, address,
ethers.utils.parseEther("10.0").toHexString(), ethers.utils.parseEther("10.0").toHexString(),
]); ]);
} }
async function impersonate(owner, account, token0, decimals) { async function impersonate(owner: string, account: any, token0: string, decimals: BigNumberish | undefined) {
const tokenArtifact = await artifacts.readArtifact( const tokenArtifact = await artifacts.readArtifact(
"@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20" "@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20"
); );

View File

@ -1,27 +1,19 @@
import { expect } from "chai"; import { expect } from "chai";
import hre from "hardhat"; import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle;
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"; import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"; import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { encodeFlashcastData } from "../../../scripts/tests/encodeFlashcastData.js";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addLiquidity } from "../../../scripts/tests/addLiquidity"; import { addLiquidity } from "../../../scripts/tests/addLiquidity";
import { addresses } from "../../../scripts/constant/addresses"; import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis"; import { abis } from "../../../scripts/constant/abis";
import { constants } from "../../../scripts/constant/constant"; import type { Signer, Contract } from "ethers";
import { tokens } from "../../../scripts/constant/tokens";
import { import { abi } from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json";
abi: nftManagerAbi, import { ConnectV2UniswapV3__factory } from "../../../typechain";
} from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json";
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 = { const FeeAmount = {
LOW: 500, LOW: 500,
@ -29,7 +21,7 @@ const FeeAmount = {
HIGH: 10000, HIGH: 10000,
}; };
const TICK_SPACINGS = { const TICK_SPACINGS: Record<number, number> = {
500: 10, 500: 10,
3000: 60, 3000: 60,
10000: 200, 10000: 200,
@ -38,18 +30,18 @@ const TICK_SPACINGS = {
const USDT_ADDR = "0xdac17f958d2ee523a2206206994597c13d831ec7"; const USDT_ADDR = "0xdac17f958d2ee523a2206206994597c13d831ec7";
const DAI_ADDR = "0x6b175474e89094c44da98b954eedeac495271d0f"; const DAI_ADDR = "0x6b175474e89094c44da98b954eedeac495271d0f";
let tokenIds = []; let tokenIds: any[] = [];
let liquidities = []; let liquidities: any[] = [];
const abiCoder = ethers.utils.defaultAbiCoder; const abiCoder = ethers.utils.defaultAbiCoder;
describe("UniswapV3", function () { describe("UniswapV3", function() {
const connectorName = "UniswapV3-v1"; const connectorName = "UniswapV3-v1";
let dsaWallet0; let dsaWallet0: any;
let masterSigner; let masterSigner: Signer;
let instaConnectorsV2; let instaConnectorsV2: Contract;
let connector; let connector: Contract;
let nftManager; let nftManager: Contract;
const wallets = provider.getWallets(); const wallets = provider.getWallets();
const [wallet0, wallet1, wallet2, wallet3] = wallets; const [wallet0, wallet1, wallet2, wallet3] = wallets;
@ -59,43 +51,44 @@ describe("UniswapV3", function () {
params: [ params: [
{ {
forking: { forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url, jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13005785, blockNumber: 13005785,
}, },
}, },
], ],
}); });
masterSigner = await getMasterSigner(wallet3); masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt( instaConnectorsV2 = await ethers.getContractAt(
abis.core.connectorsV2, abis.core.connectorsV2,
addresses.core.connectorsV2 addresses.core.connectorsV2
); );
nftManager = await ethers.getContractAt( nftManager = await ethers.getContractAt(
nftManagerAbi, abi,
"0xC36442b4a4522E871399CD717aBDD847Ab11FE88" "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
); );
connector = await deployAndEnableConnector({ connector = await deployAndEnableConnector({
connectorName, connectorName,
contractArtifact: connectV2UniswapV3Artifacts, contractArtifact: ConnectV2UniswapV3__factory,
signer: masterSigner, signer: masterSigner,
connectors: instaConnectorsV2, connectors: instaConnectorsV2,
}); });
console.log("Connector address", connector.address); console.log("Connector address", connector.address);
}); });
it("Should have contracts deployed.", async function () { it("Should have contracts deployed.", async function() {
expect(!!instaConnectorsV2.address).to.be.true; expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true; expect(!!connector.address).to.be.true;
expect(!!masterSigner.address).to.be.true; expect(!!(await masterSigner.getAddress())).to.be.true;
}); });
describe("DSA wallet setup", function () { describe("DSA wallet setup", function() {
it("Should build DSA v2", async function () { it("Should build DSA v2", async function() {
dsaWallet0 = await buildDSAv2(wallet0.address); dsaWallet0 = await buildDSAv2(wallet0.address);
expect(!!dsaWallet0.address).to.be.true; expect(!!dsaWallet0.address).to.be.true;
}); });
it("Deposit ETH & DAI into DSA wallet", async function () { it("Deposit ETH & DAI into DSA wallet", async function() {
await wallet0.sendTransaction({ await wallet0.sendTransaction({
to: dsaWallet0.address, to: dsaWallet0.address,
value: ethers.utils.parseEther("10"), value: ethers.utils.parseEther("10"),
@ -111,7 +104,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({ await wallet0.sendTransaction({
to: dsaWallet0.address, to: dsaWallet0.address,
value: ethers.utils.parseEther("10"), value: ethers.utils.parseEther("10"),
@ -128,11 +121,11 @@ describe("UniswapV3", function () {
}); });
}); });
describe("Main", function () { describe("Main", function() {
it("Should mint successfully", async function () { it("Should mint successfully", async function() {
const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH
const daiAmount = ethers.utils.parseEther("400"); // 1 ETH const daiAmount = ethers.utils.parseEther("400"); // 1 ETH
const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12); // 1 ETH const usdtAmount = Number(ethers.utils.parseEther("400")) / Math.pow(10, 12); // 1 ETH
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
const getIds = ["0", "0"]; const getIds = ["0", "0"];
@ -197,14 +190,14 @@ describe("UniswapV3", function () {
dsaWallet0.on( dsaWallet0.on(
"LogCast", "LogCast",
( (
origin, origin: any,
sender, sender: any,
value, value: any,
targetNames, targetNames: any,
targets, targets: any,
eventNames, eventNames: any,
eventParams, eventParams: any,
event event: any
) => { ) => {
const params = abiCoder.decode( const params = abiCoder.decode(
["uint256", "uint256", "uint256", "uint256", "int24", "int24"], ["uint256", "uint256", "uint256", "uint256", "int24", "int24"],
@ -237,11 +230,9 @@ describe("UniswapV3", function () {
expect(data.liquidity).to.be.equals(liquidities[0]); expect(data.liquidity).to.be.equals(liquidities[0]);
}).timeout(10000000000); }).timeout(10000000000);
it("Should deposit successfully", async function () { it("Should deposit successfully", async function() {
const daiAmount = ethers.utils.parseEther("400"); // 1 ETH const daiAmount = ethers.utils.parseEther("400"); // 1 ETH
const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH const ethAmount = ethers.utils.parseEther("0.1"); // 1 ETH
const usdtAmount = ethers.utils.parseEther("400") / Math.pow(10, 12); // 1 ETH
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
const getIds = ["0", "0"]; const getIds = ["0", "0"];
const setId = "0"; const setId = "0";
@ -270,14 +261,14 @@ describe("UniswapV3", function () {
dsaWallet0.on( dsaWallet0.on(
"LogCast", "LogCast",
( (
origin, origin: any,
sender, sender: any,
value, value: any,
targetNames, targetNames: any,
targets, targets: any,
eventNames, eventNames: any,
eventParams, eventParams: any,
event event: any
) => { ) => {
const params = abiCoder.decode( const params = abiCoder.decode(
["uint256", "uint256", "uint256", "uint256"], ["uint256", "uint256", "uint256", "uint256"],
@ -303,7 +294,7 @@ describe("UniswapV3", function () {
expect(data.liquidity).to.be.equals(liquidities[0]); expect(data.liquidity).to.be.equals(liquidities[0]);
}); });
it("Should withdraw successfully", async function () { it("Should withdraw successfully", async function() {
const getId = "0"; const getId = "0";
const setIds = ["0", "0"]; const setIds = ["0", "0"];
@ -332,7 +323,7 @@ describe("UniswapV3", function () {
expect(data1.liquidity.toNumber()).to.be.equals(0); 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 ethAmount = ethers.utils.parseEther("0.2"); // 1 ETH
const daiAmount = ethers.utils.parseEther("800"); // 1 ETH const daiAmount = ethers.utils.parseEther("800"); // 1 ETH
const getIds = ["0", "0"]; const getIds = ["0", "0"];
@ -352,7 +343,7 @@ describe("UniswapV3", function () {
const receipt = await tx.wait(); const receipt = await tx.wait();
}); });
it("Should burn successfully", async function () { it("Should burn successfully", async function() {
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
@ -369,7 +360,7 @@ describe("UniswapV3", function () {
}); });
}); });
const getMinTick = (tickSpacing) => const getMinTick = (tickSpacing: number) =>
Math.ceil(-887272 / tickSpacing) * tickSpacing; Math.ceil(-887272 / tickSpacing) * tickSpacing;
const getMaxTick = (tickSpacing) => const getMaxTick = (tickSpacing: number) =>
Math.floor(887272 / tickSpacing) * tickSpacing; Math.floor(887272 / tickSpacing) * tickSpacing;

View File

@ -3,18 +3,18 @@ import hre from "hardhat";
const { web3, deployments, waffle, ethers } = hre; const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle const { provider, deployContract } = waffle
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector.js"; import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { encodeSpells } from "../../../scripts/tests/encodeSpells.js"; import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { addLiquidity } from "../../../scripts/tests/addLiquidity"; import { addLiquidity } from "../../../scripts/tests/addLiquidity";
import { addresses } from "../../../scripts/constant/addresses"; import { addresses } from "../../../scripts/constant/addresses";
import { abis } from "../../../scripts/constant/abis"; import { abis } from "../../../scripts/constant/abis";
import { abi: nftManagerAbi } from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json" import { abi } from "@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json"
import type { Signer, Contract } from "ethers";
import connectV2UniswapStakerArtifacts from "../../artifacts/contracts/mainnet/connectors/uniswap/v3_staker/main.sol/ConnectV2UniswapV3Staker.json"; import { ConnectV2UniswapV3Staker__factory, ConnectV2UniswapV3__factory } from "../../../typechain";
import connectV2UniswapV3Artifacts from "../../artifacts/contracts/mainnet/connectors/uniswap/v3/main.sol/ConnectV2UniswapV3.json";
const FeeAmount = { const FeeAmount = {
LOW: 500, LOW: 500,
@ -22,7 +22,7 @@ const FeeAmount = {
HIGH: 10000, HIGH: 10000,
} }
const TICK_SPACINGS = { const TICK_SPACINGS: Record<number, number> = {
500: 10, 500: 10,
3000: 60, 3000: 60,
10000: 200 10000: 200
@ -32,7 +32,7 @@ const DAI_ADDR = "0x6b175474e89094c44da98b954eedeac495271d0f"
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
const INST_ADDR = "0x6f40d4a6237c257fff2db00fa0510deeecd303eb" const INST_ADDR = "0x6f40d4a6237c257fff2db00fa0510deeecd303eb"
let tokenIds = [] let tokenIds: any[] = []
const abiCoder = ethers.utils.defaultAbiCoder const abiCoder = ethers.utils.defaultAbiCoder
describe("UniswapV3", function () { describe("UniswapV3", function () {
@ -44,6 +44,7 @@ describe("UniswapV3", function () {
let instaConnectorsV2: any; let instaConnectorsV2: any;
let connector: any; let connector: any;
let startTime: any, endTime: any; let startTime: any, endTime: any;
let nftManager: Contract;
const wallets = provider.getWallets() const wallets = provider.getWallets()
const [wallet0, wallet1, wallet2, wallet3] = wallets const [wallet0, wallet1, wallet2, wallet3] = wallets
@ -53,18 +54,19 @@ describe("UniswapV3", function () {
params: [ params: [
{ {
forking: { forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url, jsonRpcUrl: hre.config.networks.hardhat.forking.url,
blockNumber: 13300000, blockNumber: 13300000,
}, },
}, },
], ],
}); });
masterSigner = await getMasterSigner(wallet3) masterSigner = await getMasterSigner()
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2); instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
let nftManager = await ethers.getContractAt(nftManagerAbi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"); nftManager = await ethers.getContractAt(abi, "0xC36442b4a4522E871399CD717aBDD847Ab11FE88");
connector = await deployAndEnableConnector({ connector = await deployAndEnableConnector({
connectorName: connectorStaker, connectorName: connectorStaker,
contractArtifact: connectV2UniswapStakerArtifacts, contractArtifact: ConnectV2UniswapV3Staker__factory,
signer: masterSigner, signer: masterSigner,
connectors: instaConnectorsV2 connectors: instaConnectorsV2
}) })
@ -72,7 +74,7 @@ describe("UniswapV3", function () {
let uniswapConnector = await deployAndEnableConnector({ let uniswapConnector = await deployAndEnableConnector({
connectorName: connectorUniswap, connectorName: connectorUniswap,
contractArtifact: connectV2UniswapV3Artifacts, contractArtifact: ConnectV2UniswapV3__factory,
signer: masterSigner, signer: masterSigner,
connectors: instaConnectorsV2 connectors: instaConnectorsV2
}); });
@ -161,7 +163,7 @@ describe("UniswapV3", function () {
let receipt = await tx.wait() let receipt = await tx.wait()
let castEvent = new Promise((resolve, reject) => { let castEvent = new Promise((resolve, reject) => {
dsaWallet0.on('LogCast', (origin, sender, value, targetNames, targets, eventNames, eventParams, event) => { dsaWallet0.on('LogCast', (origin: any, sender: any, value: any, targetNames: any, targets: any, eventNames: any, eventParams: any, event: any) => {
const params = abiCoder.decode(["uint256", "uint256", "uint256", "uint256", "int24", "int24"], eventParams[0]); const params = abiCoder.decode(["uint256", "uint256", "uint256", "uint256", "int24", "int24"], eventParams[0]);
const params1 = abiCoder.decode(["uint256", "uint256", "uint256", "uint256", "int24", "int24"], eventParams[1]); const params1 = abiCoder.decode(["uint256", "uint256", "uint256", "uint256", "int24", "int24"], eventParams[1]);
tokenIds.push(params[0]); tokenIds.push(params[0]);
@ -213,7 +215,7 @@ describe("UniswapV3", function () {
let receipt = await tx.wait() let receipt = await tx.wait()
let castEvent = new Promise((resolve, reject) => { let castEvent = new Promise((resolve, reject) => {
dsaWallet0.on('LogCast', (origin, sender, value, targetNames, targets, eventNames, eventParams, event) => { dsaWallet0.on('LogCast', (origin: any, sender: any, value: any, targetNames: any, targets: any, eventNames: any, eventParams: any, event: any) => {
const params = abiCoder.decode(["bytes32", "address", "address", "uint256", "uint256", "uint256"], eventParams[0]); 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 params1 = abiCoder.decode(["bytes32", "address", "address", "uint256", "uint256", "uint256"], eventParams[1]);
event.removeListener(); event.removeListener();
@ -226,7 +228,7 @@ describe("UniswapV3", function () {
}, 60000) }, 60000)
}); });
let event = await castEvent let event: any = await castEvent
startTime = event.start; startTime = event.start;
endTime = event.end; endTime = event.end;
}); });
@ -351,5 +353,5 @@ describe("UniswapV3", function () {
}) })
}) })
const getMinTick = (tickSpacing) => Math.ceil(-887272 / tickSpacing) * tickSpacing const getMinTick = (tickSpacing: number) => Math.ceil(-887272 / tickSpacing) * tickSpacing
const getMaxTick = (tickSpacing) => Math.floor(887272 / tickSpacing) * tickSpacing const getMaxTick = (tickSpacing: number) => Math.floor(887272 / tickSpacing) * tickSpacing

View File

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

@ -1271,6 +1271,13 @@
dependencies: dependencies:
"@types/node" "*" "@types/node" "*"
"@types/chai-as-promised@^7.1.4":
"integrity" "sha512-1y3L1cHePcIm5vXkh1DSGf/zQq5n5xDKG1fpCvf18+uOkpce0Z1ozNFPkyWsVswK7ntN1sZBw3oU6gmN+pDUcA=="
"resolved" "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.4.tgz"
"version" "7.1.4"
dependencies:
"@types/chai" "*"
"@types/chai@*", "@types/chai@^4.2.22": "@types/chai@*", "@types/chai@^4.2.22":
"integrity" "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ==" "integrity" "sha512-tFfcE+DSTzWAgifkjik9AySNqIyNoYwmR+uecPwwD/XRNfvOjmC/FjCxpiUGDkDVDphPfCUecSQVFw+lN3M3kQ=="
"resolved" "https://registry.npmjs.org/@types/chai/-/chai-4.2.22.tgz" "resolved" "https://registry.npmjs.org/@types/chai/-/chai-4.2.22.tgz"