hardhat.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import "@nomiclabs/hardhat-waffle";
  2. import "@typechain/hardhat";
  3. import "hardhat-gas-reporter";
  4. import "solidity-coverage";
  5. import "./tasks/accounts";
  6. import "./tasks/clean";
  7. import "./tasks/deployers";
  8. import { resolve } from "path";
  9. import { config as dotenvConfig } from "dotenv";
  10. import { HardhatUserConfig } from "hardhat/config";
  11. import { NetworkUserConfig } from "hardhat/types";
  12. dotenvConfig({ path: resolve(__dirname, "./.env") });
  13. const chainIds = {
  14. ganache: 1337,
  15. goerli: 5,
  16. hardhat: 31337,
  17. kovan: 42,
  18. mainnet: 1,
  19. rinkeby: 4,
  20. ropsten: 3,
  21. };
  22. // Ensure that we have all the environment variables we need.
  23. const mnemonic: string | undefined = process.env.MNEMONIC;
  24. if (!mnemonic) {
  25. throw new Error("Please set your MNEMONIC in a .env file");
  26. }
  27. const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
  28. if (!infuraApiKey) {
  29. throw new Error("Please set your INFURA_API_KEY in a .env file");
  30. }
  31. function getChainConfig(network: keyof typeof chainIds): NetworkUserConfig {
  32. const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
  33. return {
  34. accounts: {
  35. count: 10,
  36. mnemonic,
  37. path: "m/44'/60'/0'/0",
  38. },
  39. chainId: chainIds[network],
  40. url,
  41. };
  42. }
  43. const config: HardhatUserConfig = {
  44. defaultNetwork: "hardhat",
  45. gasReporter: {
  46. currency: "USD",
  47. enabled: process.env.REPORT_GAS ? true : false,
  48. excludeContracts: [],
  49. src: "./contracts",
  50. },
  51. networks: {
  52. hardhat: {
  53. accounts: {
  54. mnemonic,
  55. },
  56. chainId: chainIds.hardhat,
  57. // See https://github.com/sc-forks/solidity-coverage/issues/652
  58. hardfork: process.env.CODE_COVERAGE ? "berlin" : "london",
  59. },
  60. goerli: getChainConfig("goerli"),
  61. kovan: getChainConfig("kovan"),
  62. rinkeby: getChainConfig("rinkeby"),
  63. ropsten: getChainConfig("ropsten"),
  64. },
  65. paths: {
  66. artifacts: "./artifacts",
  67. cache: "./cache",
  68. sources: "./contracts",
  69. tests: "./test",
  70. },
  71. solidity: {
  72. version: "0.8.6",
  73. settings: {
  74. metadata: {
  75. // Not including the metadata hash
  76. // https://github.com/paulrberg/solidity-template/issues/31
  77. bytecodeHash: "none",
  78. },
  79. // Disable the optimizer when debugging
  80. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  81. optimizer: {
  82. enabled: true,
  83. runs: 800,
  84. },
  85. },
  86. },
  87. typechain: {
  88. outDir: "typechain",
  89. target: "ethers-v5",
  90. },
  91. };
  92. export default config;