hardhat.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.20',
  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. // Extra modules
  38. coverage: {
  39. type: 'boolean',
  40. default: false,
  41. },
  42. gas: {
  43. alias: 'enableGasReport',
  44. type: 'boolean',
  45. default: false,
  46. },
  47. coinmarketcap: {
  48. alias: 'coinmarketcapApiKey',
  49. type: 'string',
  50. },
  51. });
  52. require('@nomicfoundation/hardhat-chai-matchers');
  53. require('@nomicfoundation/hardhat-ethers');
  54. require('hardhat-exposed');
  55. require('hardhat-gas-reporter');
  56. require('hardhat-ignore-warnings');
  57. require('solidity-coverage');
  58. require('solidity-docgen');
  59. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  60. require(path.join(__dirname, 'hardhat', f));
  61. }
  62. const withOptimizations = argv.gas || argv.coverage || argv.compileMode === 'production';
  63. const allowUnlimitedContractSize = argv.gas || argv.coverage || argv.compileMode === 'development';
  64. /**
  65. * @type import('hardhat/config').HardhatUserConfig
  66. */
  67. module.exports = {
  68. solidity: {
  69. version: argv.compiler,
  70. settings: {
  71. optimizer: {
  72. enabled: withOptimizations,
  73. runs: 200,
  74. },
  75. viaIR: withOptimizations && argv.ir,
  76. outputSelection: { '*': { '*': ['storageLayout'] } },
  77. },
  78. },
  79. warnings: {
  80. 'contracts-exposed/**/*': {
  81. 'code-size': 'off',
  82. 'initcode-size': 'off',
  83. },
  84. '*': {
  85. 'code-size': withOptimizations,
  86. 'unused-param': !argv.coverage, // coverage causes unused-param warnings
  87. default: 'error',
  88. },
  89. },
  90. networks: {
  91. hardhat: {
  92. allowUnlimitedContractSize,
  93. initialBaseFeePerGas: argv.coverage ? 0 : undefined,
  94. },
  95. },
  96. exposed: {
  97. imports: true,
  98. initializers: true,
  99. exclude: ['vendor/**/*'],
  100. },
  101. gasReporter: {
  102. enabled: argv.gas,
  103. showMethodSig: true,
  104. currency: 'USD',
  105. coinmarketcap: argv.coinmarketcap,
  106. },
  107. paths: {
  108. sources: argv.src,
  109. },
  110. docgen: require('./docs/config'),
  111. };