hardhat.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import "@nomiclabs/hardhat-waffle";
  2. import "@nomiclabs/hardhat-etherscan";
  3. import "@typechain/hardhat";
  4. import "hardhat-gas-reporter";
  5. import "solidity-coverage";
  6. import "./tasks/accounts";
  7. import "./tasks/deploy";
  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. // Ensure that we have all the environment variables we need.
  14. const mnemonic: string | undefined = process.env.MNEMONIC;
  15. if (!mnemonic) {
  16. throw new Error("Please set your MNEMONIC in a .env file");
  17. }
  18. const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
  19. if (!infuraApiKey) {
  20. throw new Error("Please set your INFURA_API_KEY in a .env file");
  21. }
  22. const chainIds = {
  23. arbitrumOne: 42161,
  24. avalanche: 43114,
  25. bsc: 56,
  26. goerli: 5,
  27. hardhat: 31337,
  28. kovan: 42,
  29. mainnet: 1,
  30. optimism: 10,
  31. polygon: 137,
  32. rinkeby: 4,
  33. ropsten: 3,
  34. };
  35. function getChainConfig(network: keyof typeof chainIds): NetworkUserConfig {
  36. const url: string = "wss://" + network + ".infura.io/ws/v3/" + infuraApiKey;
  37. return {
  38. accounts: {
  39. count: 10,
  40. mnemonic,
  41. path: "m/44'/60'/0'/0",
  42. },
  43. chainId: chainIds[network],
  44. url,
  45. };
  46. }
  47. const config: HardhatUserConfig = {
  48. defaultNetwork: "hardhat",
  49. etherscan: {
  50. apiKey: {
  51. arbitrumOne: process.env.ARBSCAN_API_KEY,
  52. avalanche: process.env.SNOWTRACE_API_KEY,
  53. bsc: process.env.BSCSCAN_API_KEY,
  54. goerli: process.env.ETHERSCAN_API_KEY,
  55. kovan: process.env.ETHERSCAN_API_KEY,
  56. mainnet: process.env.ETHERSCAN_API_KEY,
  57. optimisticEthereum: process.env.OPTIMISM_API_KEY,
  58. polygon: process.env.POLYGONSCAN_API_KEY,
  59. rinkeby: process.env.ETHERSCAN_API_KEY,
  60. ropsten: process.env.ETHERSCAN_API_KEY,
  61. },
  62. },
  63. gasReporter: {
  64. currency: "USD",
  65. enabled: process.env.REPORT_GAS ? true : false,
  66. excludeContracts: [],
  67. src: "./contracts",
  68. },
  69. networks: {
  70. hardhat: {
  71. accounts: {
  72. mnemonic,
  73. },
  74. chainId: chainIds.hardhat,
  75. },
  76. arbitrumOne: getChainConfig("arbitrumOne"),
  77. avalanche: getChainConfig("avalanche"),
  78. bsc: getChainConfig("bsc"),
  79. goerli: getChainConfig("goerli"),
  80. kovan: getChainConfig("kovan"),
  81. mainnet: getChainConfig("mainnet"),
  82. optimism: getChainConfig("optimism"),
  83. polygon: getChainConfig("polygon"),
  84. rinkeby: getChainConfig("rinkeby"),
  85. ropsten: getChainConfig("ropsten"),
  86. },
  87. paths: {
  88. artifacts: "./artifacts",
  89. cache: "./cache",
  90. sources: "./contracts",
  91. tests: "./test",
  92. },
  93. solidity: {
  94. version: "0.8.9",
  95. settings: {
  96. metadata: {
  97. // Not including the metadata hash
  98. // https://github.com/paulrberg/solidity-template/issues/31
  99. bytecodeHash: "none",
  100. },
  101. // Disable the optimizer when debugging
  102. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  103. optimizer: {
  104. enabled: true,
  105. runs: 800,
  106. },
  107. },
  108. },
  109. typechain: {
  110. outDir: "src/types",
  111. target: "ethers-v5",
  112. },
  113. };
  114. export default config;