hardhat.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /// ENVVAR
  2. // - COMPILE_VERSION: compiler version (default: 0.8.20)
  3. // - SRC: contracts folder to compile (default: contracts)
  4. // - COMPILE_MODE: production modes enables optimizations (default: development)
  5. // - IR: enable IR compilation (default: false)
  6. // - COVERAGE: enable coverage report
  7. // - ENABLE_GAS_REPORT: enable gas report
  8. // - COINMARKETCAP: coinmarkercat api key for USD value in gas report
  9. // - CI: output gas report to file instead of stdout
  10. const fs = require('fs');
  11. const path = require('path');
  12. const { argv } = require('yargs/yargs')()
  13. .env('')
  14. .options({
  15. // Compilation settings
  16. compiler: {
  17. alias: 'compileVersion',
  18. type: 'string',
  19. default: '0.8.24',
  20. },
  21. src: {
  22. alias: 'source',
  23. type: 'string',
  24. default: 'contracts',
  25. },
  26. mode: {
  27. alias: 'compileMode',
  28. type: 'string',
  29. choices: ['production', 'development'],
  30. default: 'development',
  31. },
  32. ir: {
  33. alias: 'enableIR',
  34. type: 'boolean',
  35. default: false,
  36. },
  37. evm: {
  38. alias: 'evmVersion',
  39. type: 'string',
  40. default: 'cancun',
  41. },
  42. // Extra modules
  43. coverage: {
  44. type: 'boolean',
  45. default: false,
  46. },
  47. gas: {
  48. alias: 'enableGasReport',
  49. type: 'boolean',
  50. default: false,
  51. },
  52. coinmarketcap: {
  53. alias: 'coinmarketcapApiKey',
  54. type: 'string',
  55. },
  56. });
  57. require('@nomicfoundation/hardhat-chai-matchers');
  58. require('@nomicfoundation/hardhat-ethers');
  59. require('hardhat-exposed');
  60. require('hardhat-gas-reporter');
  61. require('hardhat-ignore-warnings');
  62. require('solidity-coverage');
  63. require('solidity-docgen');
  64. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  65. require(path.join(__dirname, 'hardhat', f));
  66. }
  67. const withOptimizations = argv.gas || argv.coverage || argv.compileMode === 'production';
  68. const allowUnlimitedContractSize = argv.gas || argv.coverage || argv.compileMode === 'development';
  69. /**
  70. * @type import('hardhat/config').HardhatUserConfig
  71. */
  72. module.exports = {
  73. solidity: {
  74. version: argv.compiler,
  75. settings: {
  76. optimizer: {
  77. enabled: withOptimizations,
  78. runs: 200,
  79. },
  80. evmVersion: argv.evm,
  81. viaIR: withOptimizations && argv.ir,
  82. outputSelection: { '*': { '*': ['storageLayout'] } },
  83. },
  84. },
  85. warnings: {
  86. 'contracts-exposed/**/*': {
  87. 'code-size': 'off',
  88. 'initcode-size': 'off',
  89. },
  90. '*': {
  91. 'code-size': withOptimizations,
  92. 'unused-param': !argv.coverage, // coverage causes unused-param warnings
  93. 'transient-storage': false,
  94. default: 'error',
  95. },
  96. },
  97. networks: {
  98. hardhat: {
  99. hardfork: argv.evm,
  100. allowUnlimitedContractSize,
  101. initialBaseFeePerGas: argv.coverage ? 0 : undefined,
  102. },
  103. },
  104. exposed: {
  105. imports: true,
  106. initializers: true,
  107. exclude: ['vendor/**/*', '**/*WithInit.sol'],
  108. },
  109. gasReporter: {
  110. enabled: argv.gas,
  111. showMethodSig: true,
  112. includeBytecodeInJSON: true,
  113. currency: 'USD',
  114. coinmarketcap: argv.coinmarketcap,
  115. },
  116. paths: {
  117. sources: argv.src,
  118. },
  119. docgen: require('./docs/config'),
  120. };