hardhat.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import "@nomiclabs/hardhat-etherscan";
  2. import "@nomiclabs/hardhat-waffle";
  3. import "@typechain/hardhat";
  4. import { config as dotenvConfig } from "dotenv";
  5. import "hardhat-gas-reporter";
  6. import { HardhatUserConfig } from "hardhat/config";
  7. import { NetworkUserConfig } from "hardhat/types";
  8. import { resolve } from "path";
  9. import "solidity-coverage";
  10. import "./tasks/accounts";
  11. import "./tasks/deploy";
  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. "arbitrum-mainnet": 42161,
  24. avalanche: 43114,
  25. bsc: 56,
  26. hardhat: 31337,
  27. mainnet: 1,
  28. "optimism-mainnet": 10,
  29. "polygon-mainnet": 137,
  30. "polygon-mumbai": 80001,
  31. rinkeby: 4,
  32. };
  33. function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
  34. let jsonRpcUrl: string;
  35. switch (chain) {
  36. case "avalanche":
  37. jsonRpcUrl = "https://api.avax.network/ext/bc/C/rpc";
  38. break;
  39. case "bsc":
  40. jsonRpcUrl = "https://bsc-dataseed1.binance.org";
  41. break;
  42. default:
  43. jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey;
  44. }
  45. return {
  46. accounts: {
  47. count: 10,
  48. mnemonic,
  49. path: "m/44'/60'/0'/0",
  50. },
  51. chainId: chainIds[chain],
  52. url: jsonRpcUrl,
  53. };
  54. }
  55. const config: HardhatUserConfig = {
  56. defaultNetwork: "hardhat",
  57. etherscan: {
  58. apiKey: {
  59. arbitrumOne: process.env.ARBISCAN_API_KEY,
  60. avalanche: process.env.SNOWTRACE_API_KEY,
  61. bsc: process.env.BSCSCAN_API_KEY,
  62. mainnet: process.env.ETHERSCAN_API_KEY,
  63. optimisticEthereum: process.env.OPTIMISM_API_KEY,
  64. polygon: process.env.POLYGONSCAN_API_KEY,
  65. polygonMumbai: process.env.POLYGONSCAN_API_KEY,
  66. rinkeby: process.env.ETHERSCAN_API_KEY,
  67. },
  68. },
  69. gasReporter: {
  70. currency: "USD",
  71. enabled: process.env.REPORT_GAS ? true : false,
  72. excludeContracts: [],
  73. src: "./contracts",
  74. },
  75. networks: {
  76. hardhat: {
  77. accounts: {
  78. mnemonic,
  79. },
  80. chainId: chainIds.hardhat,
  81. },
  82. arbitrum: getChainConfig("arbitrum-mainnet"),
  83. avalanche: getChainConfig("avalanche"),
  84. bsc: getChainConfig("bsc"),
  85. mainnet: getChainConfig("mainnet"),
  86. optimism: getChainConfig("optimism-mainnet"),
  87. "polygon-mainnet": getChainConfig("polygon-mainnet"),
  88. "polygon-mumbai": getChainConfig("polygon-mumbai"),
  89. rinkeby: getChainConfig("rinkeby"),
  90. },
  91. paths: {
  92. artifacts: "./artifacts",
  93. cache: "./cache",
  94. sources: "./contracts",
  95. tests: "./test",
  96. },
  97. solidity: {
  98. version: "0.8.13",
  99. settings: {
  100. metadata: {
  101. // Not including the metadata hash
  102. // https://github.com/paulrberg/solidity-template/issues/31
  103. bytecodeHash: "none",
  104. },
  105. // Disable the optimizer when debugging
  106. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  107. optimizer: {
  108. enabled: true,
  109. runs: 800,
  110. },
  111. },
  112. },
  113. typechain: {
  114. outDir: "src/types",
  115. target: "ethers-v5",
  116. },
  117. };
  118. export default config;