Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/hdev 345 unit tests mainnet #29

Draft
wants to merge 31 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
316e825
Unit Tests: Deposit and swaps
motoshifin Nov 9, 2021
ce54a84
withdraw
motoshifin Nov 9, 2021
1a902bd
- deployment test file using new config
motoshifin Nov 10, 2021
71743bd
debugging NETWORK env on CI
motoshifin Nov 10, 2021
d264c01
debugging NETWORK env on CI
motoshifin Nov 10, 2021
3de5ce4
Merge branch 'develop' into features/hdev-345-unit-tests
motoshifin Nov 23, 2021
fa88a12
deployed assimilators
motoshifin Nov 24, 2021
6b9fc67
- hh config default rpc_url and block_no for hh network
motoshifin Nov 24, 2021
a535b42
- hh network BLOCK_NO from config
motoshifin Nov 24, 2021
c8f2047
quote assimilator refactor
motoshifin Nov 24, 2021
eaeb8c6
- eurs, xsgd and fxphp only(mainnet)
motoshifin Nov 28, 2021
ee470c7
curve tests, eurs, xsgd and fxphp
motoshifin Nov 29, 2021
4021807
- eurs in setup
motoshifin Nov 29, 2021
3d2d826
liquidity tests, updated token constants
motoshifin Nov 29, 2021
3ec88d7
transact tests
motoshifin Nov 29, 2021
426358e
updated blocks that works on eurs, xsgd and fxphp
motoshifin Nov 29, 2021
9cf2944
removed it.only
motoshifin Nov 30, 2021
14d1475
refactor constants
motoshifin Nov 30, 2021
d785c34
Curve.test.ts wip
motoshifin Nov 30, 2021
700f3a8
unit tests put back cadc curve
motoshifin Nov 30, 2021
7031938
fixed viewDeposit and viewWithdraw in curve.test.ts
motoshifin Dec 2, 2021
2c6681e
fixed invariant checking for fxphp
motoshifin Dec 12, 2021
2b48f36
fixed swaps fxphp
motoshifin Dec 12, 2021
188a9cd
enabled viewWithdraw
motoshifin Dec 12, 2021
5055693
enabled Add and remove liquidity
motoshifin Dec 12, 2021
2fb3011
fix Oracle updates between operations viewDeposit
motoshifin Dec 12, 2021
ed193f2
Oracle updates between operations viewWithdraw
motoshifin Dec 12, 2021
02a1fe4
fixed Oracle updates between operations, Add and remove liquidity EURS
motoshifin Dec 13, 2021
6644bfc
fixed Oracle updates between operations, Add and remove liquidity FXPHP
motoshifin Dec 13, 2021
3eda30c
factory test
motoshifin Dec 14, 2021
17c6818
Fixed router.test
motoshifin Dec 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ jobs:
node-version: ${{ matrix.node-version }}

- run: yarn install
- run: yarn compile && yarn test
- run: yarn compile && yarn test:mainnet
env:
INFURA_PROJECT_ID: ${{ secrets.INFURA_PROJECT_ID }}
ALCHEMY_PROJECT_ID: ${{ secrets.ALCHEMY_PROJECT_ID }}
MNEMONIC: ${{ secrets.MNEMONIC }}
- run: yarn test:matic
env:
INFURA_PROJECT_ID: ${{ secrets.INFURA_PROJECT_ID }}
ALCHEMY_PROJECT_ID: ${{ secrets.ALCHEMY_PROJECT_ID }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ scripts/deployed_contract_logs/hardhat

scripts/config/kovan
scripts/config/localhost
scripts/config/hardhat
scripts/config/hardhat
scripts/config/matic
25 changes: 20 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@ import { HardhatUserConfig } from "hardhat/config";
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-etherscan";

import { CONFIG } from "./test/Config";

const INFURA_PROJECT_ID = process.env.INFURA_PROJECT_ID;
const ALCHEMY_PROJECT_ID = process.env.ALCHEMY_PROJECT_ID;
const alchemyEndpoint = `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_PROJECT_ID}`;
const MNEMONIC = process.env.MNEMONIC;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
import { CONFIG } from "./test/Config";
const LOCALHOST = "http://127.0.0.1:8545";

let RPC_URL;
let BLOCK_NO;

if (process.env.NETWORK === 'mainnet') {
RPC_URL = `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_PROJECT_ID}`;
BLOCK_NO = CONFIG.BLOCK_NO;
} else if (process.env.NETWORK === 'matic') {
RPC_URL = `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_PROJECT_ID}`;
BLOCK_NO = CONFIG.BLOCK_NO;
} else if (process.env.NETWORK === 'kovan') {
RPC_URL = `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_PROJECT_ID}`;
BLOCK_NO = CONFIG.BLOCK_NO;
} else {
RPC_URL = `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_PROJECT_ID}`;
BLOCK_NO = CONFIG.BLOCK_NO;
}
Comment on lines +17 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a switch instead?


// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn moreww
Expand All @@ -34,8 +49,8 @@ const config: HardhatUserConfig = {
},
forking: {
enabled: true,
url: alchemyEndpoint ? alchemyEndpoint : LOCALHOST,
blockNumber: CONFIG.BLOCK_NO
url: RPC_URL,
blockNumber: BLOCK_NO
},
blockGasLimit: 20000000,
allowUnlimitedContractSize: true
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"hh:node": "hardhat node",
"compile": "hardhat compile",
"clean": "hardhat clean",
"test": "hardhat test",
"test:mainnet": "NETWORK=mainnet hardhat test",
"test:matic": "NETWORK=matic hardhat test",
"test:kovan": "NETWORK=kovan hardhat test",
"scaffold:local": "yarn hh:run scripts/testnet/scaffold.ts --network localhost",
"deploy:local:1": "hardhat run scripts/01-deploy-factory.ts --network localhost",
"deploy:local:2": "hardhat run scripts/02-deploy-assimilators.ts --network localhost",
Expand Down Expand Up @@ -166,5 +168,6 @@
"node_modules/**",
"typechain/**"
]
}
}
},
"devDependencies": {}
}
10 changes: 5 additions & 5 deletions scripts/00-verify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const hre = require("hardhat");
import { parseUnits } from "@ethersproject/units";
import { CONTRACTS } from "./config/contracts";
import { configImporterNew } from "./Utils";
import { configImporter } from "./Utils";

const QUOTED_TOKEN = 'TOKEN_ADDR_USDC';
const ASSIMILATORS = process.env.ASSIMILATORS;
Expand Down Expand Up @@ -44,7 +44,7 @@ const assimilatorsVerify = async () => {
try {
const token = assimilators[index].split('ToUsdAssimilator')[0].toUpperCase();
const fileName = `${token}ToUsdAssimilator`;
const curveAddr = require(configImporterNew(`assimilators/${fileName}.json`))[fileName];
const curveAddr = require(configImporter(`assimilators/${fileName}.json`))[fileName];

await hre.run('verify:verify', {
address: curveAddr
Expand Down Expand Up @@ -94,11 +94,11 @@ const curvesVerify = async () => {

const fileName = `${tokenSymbol}Curves`;
const fullFileName = `${fileName}.json`;
const curveAddr = require(configImporterNew(`curves/${fullFileName}`))[fileName];
const curveAddr = require(configImporter(`curves/${fullFileName}`))[fileName];
const token = assimilators[index].split('ToUsdAssimilator')[0].toUpperCase();
const assimfileName = `${token}ToUsdAssimilator`;
const assimAddr = require(configImporterNew(`assimilators/${assimfileName}.json`))[assimfileName];
const quotedAssimAddr = require(configImporterNew(`assimilators/USDCToUsdAssimilator.json`))['USDCToUsdAssimilator'];
const assimAddr = require(configImporter(`assimilators/${assimfileName}.json`))[assimfileName];
const quotedAssimAddr = require(configImporter(`assimilators/USDCToUsdAssimilator.json`))['USDCToUsdAssimilator'];

await hre.run('verify:verify', {
address: curveAddr,
Expand Down
12 changes: 4 additions & 8 deletions scripts/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import mkdirp from "mkdirp";
import fs from "fs";
import { BigNumberish } from "ethers";
import { ERC20 } from "../typechain/ERC20";
import { CurveFactory, Curve } from "../typechain";
import { CurveFactory, Curve, Router } from "../typechain";
import { deployContract, getFastGasPrice } from "./common";

const NETWORK = hre.network.name;
Expand Down Expand Up @@ -79,7 +79,7 @@ export const curveConfig = async (tokenSymbol, tokenName, curveWeights, lptNames
const tokenName = tokenNameArr[index];
const fullFileName = fileObj[tokenSymbol.toUpperCase()];
const fileName = fileObj[tokenSymbol.toUpperCase()].split('.json')[0];
const baseAssimilatorAddr = require(configImporterNew(`assimilators/${fullFileName}`))[fileName];
const baseAssimilatorAddr = require(configImporter(`assimilators/${fullFileName}`))[fileName];
const quoteAssimilatorAddr = require(path.resolve(__dirname, `./config/usdcassimilator/${NETWORK}.json`)).address;
const lptName = lptNamesArr[index];

Expand Down Expand Up @@ -149,11 +149,7 @@ export const deployedLogs = async (filename, output) => {
fs.writeFileSync(outputConfigPath, JSON.stringify(output, null, 4));
};

export const configImporter = (filename) => {
return path.resolve(__dirname, `./config/${NETWORK}/${filename}.json`);
}

export const configImporterNew = (route) => {
export const configImporter = (route) => {
return path.resolve(__dirname, `./config/${NETWORK}/${route}`);
}

Expand Down Expand Up @@ -199,7 +195,7 @@ export const curveAddresses = async () => {
const fileObj = await listFiles('curves', 'Curves.json');

Object.keys(fileObj).map(key => {
let curveAddr = require(configImporterNew(`curves/${fileObj[key]}`))
let curveAddr = require(configImporter(`curves/${fileObj[key]}`))
curves[key] = curveAddr[Object.keys(curveAddr)[0]];
});

Expand Down
6 changes: 6 additions & 0 deletions scripts/halo/assimilatorConfigs/mainnet/CADC_USDC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"baseDecimals": 18,
"baseTokenAddress": "0xcadc0acd4b445166f12d2c07eac6e2544fbe2eef",
"quoteTokenAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"oracleAddress": "0xa34317DB73e77d453b1B8d04550c44D10e981C8e"
}
117 changes: 101 additions & 16 deletions test/01-Deployment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import path from "path";
import { ethers } from "hardhat";
import { Signer, Contract, ContractFactory, BigNumber, BigNumberish } from "ethers";
import chai, { expect } from "chai";
Expand All @@ -11,9 +12,8 @@ import { Router } from "../typechain/Router";

import { scaffoldTest, scaffoldHelpers } from "./Setup";
import { assert } from "console";

import { TOKENS } from "./Constants";
import { CONFIG } from "./Config";
const { TOKENS } = require(path.resolve(__dirname, `tokens/${process.env.NETWORK}/Constants.ts`));

chai.use(chaiBigNumber(BigNumber));

Expand All @@ -30,11 +30,14 @@ const DIMENSION = {
describe("Deployment", () => {
let [user1, user2]: Signer[] = [];
let [user1Address, user2Address]: string[] = [];
let assimilator = {};
let quoteAssimilatorAddr;

let cadcToUsdAssimilator: Contract;
let usdcToUsdAssimilator: Contract;
let eursToUsdAssimilator: Contract;
let xsgdToUsdAssimilator: Contract;
let cadcToUsdAssimilator: Contract;
let fxphpToUsdAssimilator: Contract;

let CurveFactory: ContractFactory;
let RouterFactory: ContractFactory;
Expand All @@ -46,7 +49,6 @@ describe("Deployment", () => {
let routerContract: Contract;

let usdc: ERC20;
let cadc: ERC20;
let erc20: ERC20;

let curvesLib: Contract;
Expand Down Expand Up @@ -84,14 +86,16 @@ describe("Deployment", () => {
({
users: [user1, user2],
userAddresses: [user1Address, user2Address],
cadcToUsdAssimilator,

usdcToUsdAssimilator,
eursToUsdAssimilator,
xsgdToUsdAssimilator,
cadcToUsdAssimilator,
fxphpToUsdAssimilator,

CurveFactory,
RouterFactory,
usdc,
cadc,
erc20,
curvesLib,
orchestratorLib,
Expand All @@ -100,6 +104,13 @@ describe("Deployment", () => {
viewLiquidityLib
} = await scaffoldTest());

assimilator = {
'EURS': eursToUsdAssimilator,
'XSGD': xsgdToUsdAssimilator,
'CADC': cadcToUsdAssimilator,
'FXPHP': fxphpToUsdAssimilator
};

curveFactoryContract = await CurveFactory.deploy();
routerContract = await RouterFactory.deploy(curveFactoryContract.address);

Expand All @@ -110,6 +121,8 @@ describe("Deployment", () => {
curveFactory,
erc20,
}));

quoteAssimilatorAddr = require(path.resolve(__dirname, `../scripts/config/usdcassimilator/${process.env.NETWORK}.json`));
});

describe("Core Contracts", async () => {
Expand All @@ -123,34 +136,106 @@ describe("Deployment", () => {
});

describe("Assimilators", async () => {
it("CadcToUsdAssimilator", () => { assert(ethers.utils.isAddress(cadcToUsdAssimilator.address)); })
it("UsdcToUsdAssimilator", () => { assert(ethers.utils.isAddress(usdcToUsdAssimilator.address)); })
it("EursToUsdAssimilator", () => { assert(ethers.utils.isAddress(eursToUsdAssimilator.address)); })
it("XsgdToUsdAssimilator", () => { assert(ethers.utils.isAddress(xsgdToUsdAssimilator.address)); })
it("EursToUsdAssimilator", () => { assert(ethers.utils.isAddress(assimilator['EURS'].address)); })
it("XsgdToUsdAssimilator", () => { assert(ethers.utils.isAddress(assimilator['XSGD'].address)); })
it("CadcToUsdAssimilator", () => { assert(ethers.utils.isAddress(assimilator['CADC'].address)); })
it("FxphpToUsdAssimilator", () => { assert(ethers.utils.isAddress(assimilator['FXPHP'].address)); })
})

describe("Curve/Pair Contract", async () => {
const NAME = "CAD Coin";
const SYMBOL = "CADC";
it("EURS:USDC", async () => {
const NAME = "EURS";
const SYMBOL = "EURS";

const { curve } = await createCurveAndSetParams({
name: NAME,
symbol: SYMBOL,
base: TOKENS.EURS.address,
quote: TOKENS.USDC.address,
baseWeight: parseUnits("0.4"),
quoteWeight: parseUnits("0.6"),
baseAssimilator: assimilator['EURS'].address,
quoteAssimilator: quoteAssimilatorAddr.address,
params: [DIMENSION.alpha, DIMENSION.beta, DIMENSION.max, DIMENSION.epsilon, DIMENSION.lambda],
});

const curveAddrA = curve.address;
const curveAddrB = await curveFactory.getCurve(TOKENS.EURS.address, TOKENS.USDC.address);

expect(ethers.utils.isAddress(curveAddrA)).true;
expect(ethers.utils.isAddress(curveAddrB)).true;
expect(curveAddrA).to.be.equal(curveAddrB);
})

it("XSGD:USDC", async () => {
const NAME = "XSGD";
const SYMBOL = "XSGD";

const { curve } = await createCurveAndSetParams({
name: NAME,
symbol: SYMBOL,
base: TOKENS.XSGD.address,
quote: TOKENS.USDC.address,
baseWeight: parseUnits("0.4"),
quoteWeight: parseUnits("0.6"),
baseAssimilator: assimilator['XSGD'].address,
quoteAssimilator: quoteAssimilatorAddr.address,
params: [DIMENSION.alpha, DIMENSION.beta, DIMENSION.max, DIMENSION.epsilon, DIMENSION.lambda],
});

const curveAddrA = curve.address;
const curveAddrB = await curveFactory.getCurve(TOKENS.XSGD.address, TOKENS.USDC.address);

expect(ethers.utils.isAddress(curveAddrA)).true;
expect(ethers.utils.isAddress(curveAddrB)).true;
expect(curveAddrA).to.be.equal(curveAddrB);
})

it("CADC:USDC", async () => {
const NAME = "CADC";
const SYMBOL = "CADC";

const { curve } = await createCurveAndSetParams({
name: NAME,
symbol: SYMBOL,
base: TOKENS.CADC.address,
quote: TOKENS.USDC.address,
baseWeight: parseUnits("0.4"),
quoteWeight: parseUnits("0.6"),
baseAssimilator: cadcToUsdAssimilator.address,
quoteAssimilator: usdcToUsdAssimilator.address,
baseAssimilator: assimilator['CADC'].address,
quoteAssimilator: quoteAssimilatorAddr.address,
params: [DIMENSION.alpha, DIMENSION.beta, DIMENSION.max, DIMENSION.epsilon, DIMENSION.lambda],
});

const curveAddrA = curve.address;
const curveAddrB = await curveFactory.getCurve(TOKENS.CADC.address, TOKENS.USDC.address);

assert(ethers.utils.isAddress(curveAddrA));
assert(ethers.utils.isAddress(curveAddrB));
expect(ethers.utils.isAddress(curveAddrA)).true;
expect(ethers.utils.isAddress(curveAddrB)).true;
expect(curveAddrA).to.be.equal(curveAddrB);
})

it("FXPHP:USDC", async () => {
const NAME = "FXPHP";
const SYMBOL = "FXPHP";

const { curve } = await createCurveAndSetParams({
name: NAME,
symbol: SYMBOL,
base: TOKENS.FXPHP.address,
quote: TOKENS.USDC.address,
baseWeight: parseUnits("0.4"),
quoteWeight: parseUnits("0.6"),
baseAssimilator: assimilator['FXPHP'].address,
quoteAssimilator: quoteAssimilatorAddr.address,
params: [DIMENSION.alpha, DIMENSION.beta, DIMENSION.max, DIMENSION.epsilon, DIMENSION.lambda],
});

const curveAddrA = curve.address;
const curveAddrB = await curveFactory.getCurve(TOKENS.FXPHP.address, TOKENS.USDC.address);

expect(ethers.utils.isAddress(curveAddrA)).true;
expect(ethers.utils.isAddress(curveAddrB)).true;
expect(curveAddrA).to.be.equal(curveAddrB);
})
})
Expand Down
Loading