hardhat.config.ts 2.8 KB

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