hardhat.config.ts 3.1 KB

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