hardhat.config.ts 3.1 KB

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