hardhat.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import "@nomicfoundation/hardhat-toolbox";
  2. import type { HardhatUserConfig } from "hardhat/config";
  3. import { vars } from "hardhat/config";
  4. import type { NetworkUserConfig } from "hardhat/types";
  5. import "./tasks/accounts";
  6. import "./tasks/lock";
  7. // Run 'npx hardhat vars setup' to see the list of variables that need to be set
  8. const mnemonic: string = vars.get("MNEMONIC");
  9. const infuraApiKey: string = vars.get("INFURA_API_KEY");
  10. const chainIds = {
  11. "arbitrum-mainnet": 42161,
  12. avalanche: 43114,
  13. bsc: 56,
  14. ganache: 1337,
  15. hardhat: 31337,
  16. mainnet: 1,
  17. "optimism-mainnet": 10,
  18. "polygon-mainnet": 137,
  19. "polygon-mumbai": 80001,
  20. sepolia: 11155111,
  21. };
  22. function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
  23. let jsonRpcUrl: string;
  24. switch (chain) {
  25. case "avalanche":
  26. jsonRpcUrl = "https://api.avax.network/ext/bc/C/rpc";
  27. break;
  28. case "bsc":
  29. jsonRpcUrl = "https://bsc-dataseed1.binance.org";
  30. break;
  31. default:
  32. jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey;
  33. }
  34. return {
  35. accounts: {
  36. count: 10,
  37. mnemonic,
  38. path: "m/44'/60'/0'/0",
  39. },
  40. chainId: chainIds[chain],
  41. url: jsonRpcUrl,
  42. };
  43. }
  44. const config: HardhatUserConfig = {
  45. defaultNetwork: "hardhat",
  46. namedAccounts: {
  47. deployer: 0,
  48. },
  49. etherscan: {
  50. apiKey: {
  51. arbitrumOne: vars.get("ARBISCAN_API_KEY", ""),
  52. avalanche: vars.get("SNOWTRACE_API_KEY", ""),
  53. bsc: vars.get("BSCSCAN_API_KEY", ""),
  54. mainnet: vars.get("ETHERSCAN_API_KEY", ""),
  55. optimisticEthereum: vars.get("OPTIMISM_API_KEY", ""),
  56. polygon: vars.get("POLYGONSCAN_API_KEY", ""),
  57. polygonMumbai: vars.get("POLYGONSCAN_API_KEY", ""),
  58. sepolia: vars.get("ETHERSCAN_API_KEY", ""),
  59. },
  60. },
  61. gasReporter: {
  62. currency: "USD",
  63. enabled: process.env.REPORT_GAS ? true : false,
  64. excludeContracts: [],
  65. src: "./contracts",
  66. },
  67. networks: {
  68. hardhat: {
  69. accounts: {
  70. mnemonic,
  71. },
  72. chainId: chainIds.hardhat,
  73. },
  74. ganache: {
  75. accounts: {
  76. mnemonic,
  77. },
  78. chainId: chainIds.ganache,
  79. url: "http://localhost:8545",
  80. },
  81. arbitrum: getChainConfig("arbitrum-mainnet"),
  82. avalanche: getChainConfig("avalanche"),
  83. bsc: getChainConfig("bsc"),
  84. mainnet: getChainConfig("mainnet"),
  85. optimism: getChainConfig("optimism-mainnet"),
  86. "polygon-mainnet": getChainConfig("polygon-mainnet"),
  87. "polygon-mumbai": getChainConfig("polygon-mumbai"),
  88. sepolia: getChainConfig("sepolia"),
  89. },
  90. paths: {
  91. artifacts: "./artifacts",
  92. cache: "./cache",
  93. sources: "./contracts",
  94. tests: "./test",
  95. },
  96. solidity: {
  97. version: "0.8.19",
  98. settings: {
  99. metadata: {
  100. // Not including the metadata hash
  101. // https://github.com/paulrberg/hardhat-template/issues/31
  102. bytecodeHash: "none",
  103. },
  104. // Disable the optimizer when debugging
  105. // https://hardhat.org/hardhat-network/#solidity-optimizer-support
  106. optimizer: {
  107. enabled: true,
  108. runs: 800,
  109. },
  110. },
  111. },
  112. typechain: {
  113. outDir: "types",
  114. target: "ethers-v6",
  115. },
  116. };
  117. export default config;