Added pool configuration manager with "config" library.

This commit is contained in:
David Racero 2020-08-21 17:11:15 +02:00
parent 82ee09caef
commit 0a173a587b
9 changed files with 920 additions and 544 deletions

0
a.out
View File

View File

@ -1,10 +1,11 @@
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import {usePlugin} from '@nomiclabs/buidler/config';
import {usePlugin, BuidlerConfig} from '@nomiclabs/buidler/config';
// @ts-ignore // @ts-ignore
import {accounts} from './test-wallets.js'; import {accounts} from './test-wallets.js';
import {eEthereumNetwork} from './helpers/types'; import {eEthereumNetwork} from './helpers/types';
import {loadConfig} from './config/loadConfig';
usePlugin('@nomiclabs/buidler-ethers'); usePlugin('@nomiclabs/buidler-ethers');
usePlugin('buidler-typechain'); usePlugin('buidler-typechain');
@ -13,6 +14,9 @@ usePlugin('@nomiclabs/buidler-waffle');
usePlugin('@nomiclabs/buidler-etherscan'); usePlugin('@nomiclabs/buidler-etherscan');
//usePlugin('buidler-gas-reporter'); //usePlugin('buidler-gas-reporter');
const config = loadConfig();
const configName = config.get('ConfigName');
const DEFAULT_BLOCK_GAS_LIMIT = 10000000; const DEFAULT_BLOCK_GAS_LIMIT = 10000000;
const DEFAULT_GAS_PRICE = 10; const DEFAULT_GAS_PRICE = 10;
const HARDFORK = 'istanbul'; const HARDFORK = 'istanbul';
@ -48,7 +52,9 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number
}; };
}; };
const config: any = { console.log(`💾 Loaded "${configName}" pool configuration .\n`);
const buidlerConfig: any = {
solc: { solc: {
version: '0.6.8', version: '0.6.8',
optimizer: {enabled: true, runs: 200}, optimizer: {enabled: true, runs: 200},
@ -95,4 +101,4 @@ const config: any = {
}, },
}; };
export default config; export default buidlerConfig;

3
config/aave.ts Normal file
View File

@ -0,0 +1,3 @@
export default {
ConfigName: 'Aave',
};

19
config/loadConfig.ts Normal file
View File

@ -0,0 +1,19 @@
import {IConfig} from 'config';
let config: IConfig;
// This function swaps NODE_ENV during the 'config' library load, to load custom config files, then keeps NODE_ENV like before.
export const loadConfig = () => {
if (config) {
return config;
}
const currentNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = process.env.POOL;
const configuration = require('config');
process.env.NODE_ENV = currentNodeEnv;
config = configuration;
return config;
};

3
config/tokensets.ts Normal file
View File

@ -0,0 +1,3 @@
export default {
ConfigName: 'TokenSets',
};

3
config/uniswap.ts Normal file
View File

@ -0,0 +1,3 @@
export default {
ConfigName: 'Uniswap',
};

1391
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,23 +5,28 @@
"scripts": { "scripts": {
"run-env": "npm i && tail -f /dev/null", "run-env": "npm i && tail -f /dev/null",
"buidler": "buidler", "buidler": "buidler",
"buidler-kovan": "buidler --network kovan", "buidler:aave": "POOL=aave buidler",
"buidler-ropsten": "buidler --network ropsten", "buidler:aave:kovan": "npm run buidler:aave -- --network kovan",
"buidler-main": "buidler --network main", "buidler:aave:ropsten": "npm run buidler:aave -- --network ropsten",
"buidler:aave:main": "npm run buidler:aave -- --network main",
"buidler:uniswap": "POOL=uniswap buidler",
"buidler:uniswap:kovan": "npm run buidler:uniswap -- --network kovan",
"buidler:uniswap:ropsten": "npm run buidler:uniswap --network ropsten",
"buidler:uniswap:main": "npm run buidler:uniswap --network main",
"buidler help": "buidler help", "buidler help": "buidler help",
"compile": "buidler compile", "compile": "buidler compile",
"types-gen": "typechain --target ethers-v5 --outDir ./types './artifacts/*.json'", "types-gen": "typechain --target ethers-v5 --outDir ./types './artifacts/*.json'",
"test": "buidler test", "test": "buidler test",
"test-scenarios": "buidler test test/__setup.spec.ts test/scenario.spec.ts", "test-scenarios": "buidler test test/__setup.spec.ts test/scenario.spec.ts",
"coverage": "buidler coverage", "coverage": "buidler coverage",
"evm:dev:migration": "buidler dev-migration", "aave:evm:dev:migration": "npm run buidler:aave -- dev-migration",
"evm:full:migration": "buidler full-migration", "aave:evm:full:migration": "buidler full-migration",
"kovan:dev:migration": "npm run buidler-kovan -- dev-migration --verify", "aave:kovan:dev:migration": "npm run buidler:aave:kovan -- dev-migration --verify",
"kovan:full:migration": "npm run buidler-kovan -- full-migration --verify", "aave:kovan:full:migration": "npm run buidler:aave:kovan -- full-migration --verify",
"ropsten:dev:migration": "npm run buidler-ropsten -- dev-migration --verify", "aave:ropsten:dev:migration": "npm run buidler:aave:ropsten -- dev-migration --verify",
"ropsten:full:migration": "npm run buidler-ropsten -- full-migration --verify", "aave:ropsten:full:migration": "npm run buidler:aave:ropsten -- full-migration --verify",
"main:dev:migration": "npm run buidler-main -- dev-migration --verify", "aave:main:dev:migration": "npm run buidler:aave:main -- dev-migration --verify",
"main:full:migration": "npm run buidler-main -- full-migration --verify" "uniswap:evm:dev:migration": "npm run buidler:uniswap -- dev-migration"
}, },
"devDependencies": { "devDependencies": {
"@nomiclabs/buidler": "1.4.4", "@nomiclabs/buidler": "1.4.4",
@ -29,12 +34,13 @@
"@nomiclabs/buidler-etherscan": "1.3.3", "@nomiclabs/buidler-etherscan": "1.3.3",
"@nomiclabs/buidler-waffle": "2.0.0", "@nomiclabs/buidler-waffle": "2.0.0",
"@openzeppelin/contracts": "3.1.0", "@openzeppelin/contracts": "3.1.0",
"@typechain/ethers-v5": "^1.0.0",
"@typechain/ethers-v4": "1.0.0", "@typechain/ethers-v4": "1.0.0",
"@typechain/ethers-v5": "^1.0.0",
"@typechain/truffle-v4": "2.0.2", "@typechain/truffle-v4": "2.0.2",
"@typechain/truffle-v5": "2.0.2", "@typechain/truffle-v5": "2.0.2",
"@typechain/web3-v1": "1.0.0", "@typechain/web3-v1": "1.0.0",
"@types/chai": "4.2.11", "@types/chai": "4.2.11",
"@types/config": "0.0.36",
"@types/lowdb": "1.0.9", "@types/lowdb": "1.0.9",
"@types/mocha": "7.0.2", "@types/mocha": "7.0.2",
"@types/node": "14.0.5", "@types/node": "14.0.5",
@ -48,6 +54,7 @@
"ethers": "5.0.8", "ethers": "5.0.8",
"husky": "^4.2.5", "husky": "^4.2.5",
"lowdb": "1.0.0", "lowdb": "1.0.0",
"node-config": "0.0.2",
"prettier": "^2.0.5", "prettier": "^2.0.5",
"prettier-plugin-solidity": "^1.0.0-alpha.53", "prettier-plugin-solidity": "^1.0.0-alpha.53",
"pretty-quick": "^2.0.1", "pretty-quick": "^2.0.1",

View File

@ -8,7 +8,7 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"downlevelIteration": true "downlevelIteration": true
}, },
"include": ["./**/*"], "include": ["./**/*", "config/.ts"],
"files": [ "files": [
"./buidler.config.ts", "./buidler.config.ts",
"node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts", "node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts",