hardhat.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /// ENVVAR
  2. // - CI: output gas report to file instead of stdout
  3. // - COVERAGE: enable coverage report
  4. // - ENABLE_GAS_REPORT: enable gas report
  5. // - COMPILE_MODE: production modes enables optimizations (default: development)
  6. // - COMPILE_VERSION: compiler version (default: 0.8.20)
  7. // - COINMARKETCAP: coinmarkercat api key for USD value in gas report
  8. const fs = require('fs');
  9. const path = require('path');
  10. const proc = require('child_process');
  11. const argv = require('yargs/yargs')()
  12. .env('')
  13. .options({
  14. coverage: {
  15. type: 'boolean',
  16. default: false,
  17. },
  18. gas: {
  19. alias: 'enableGasReport',
  20. type: 'boolean',
  21. default: false,
  22. },
  23. gasReport: {
  24. alias: 'enableGasReportPath',
  25. type: 'string',
  26. implies: 'gas',
  27. default: undefined,
  28. },
  29. mode: {
  30. alias: 'compileMode',
  31. type: 'string',
  32. choices: ['production', 'development'],
  33. default: 'development',
  34. },
  35. ir: {
  36. alias: 'enableIR',
  37. type: 'boolean',
  38. default: false,
  39. },
  40. foundry: {
  41. alias: 'hasFoundry',
  42. type: 'boolean',
  43. default: hasFoundry(),
  44. },
  45. compiler: {
  46. alias: 'compileVersion',
  47. type: 'string',
  48. default: '0.8.20',
  49. },
  50. coinmarketcap: {
  51. alias: 'coinmarketcapApiKey',
  52. type: 'string',
  53. },
  54. }).argv;
  55. require('@nomiclabs/hardhat-truffle5');
  56. require('hardhat-ignore-warnings');
  57. require('hardhat-exposed');
  58. require('solidity-docgen');
  59. argv.foundry && require('@nomicfoundation/hardhat-foundry');
  60. if (argv.foundry && argv.coverage) {
  61. throw Error('Coverage analysis is incompatible with Foundry. Disable with `FOUNDRY=false` in the environment');
  62. }
  63. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  64. require(path.join(__dirname, 'hardhat', f));
  65. }
  66. const withOptimizations = argv.gas || argv.compileMode === 'production';
  67. /**
  68. * @type import('hardhat/config').HardhatUserConfig
  69. */
  70. module.exports = {
  71. solidity: {
  72. version: argv.compiler,
  73. settings: {
  74. optimizer: {
  75. enabled: withOptimizations,
  76. runs: 200,
  77. },
  78. viaIR: withOptimizations && argv.ir,
  79. outputSelection: { '*': { '*': ['storageLayout'] } },
  80. },
  81. },
  82. warnings: {
  83. 'contracts-exposed/**/*': {
  84. 'code-size': 'off',
  85. 'initcode-size': 'off',
  86. },
  87. '*': {
  88. 'code-size': withOptimizations,
  89. 'unused-param': !argv.coverage, // coverage causes unused-param warnings
  90. default: 'error',
  91. },
  92. },
  93. networks: {
  94. hardhat: {
  95. blockGasLimit: 10000000,
  96. allowUnlimitedContractSize: !withOptimizations,
  97. },
  98. },
  99. exposed: {
  100. imports: true,
  101. initializers: true,
  102. exclude: ['vendor/**/*'],
  103. },
  104. docgen: require('./docs/config'),
  105. };
  106. if (argv.gas) {
  107. require('hardhat-gas-reporter');
  108. module.exports.gasReporter = {
  109. showMethodSig: true,
  110. currency: 'USD',
  111. outputFile: argv.gasReport,
  112. coinmarketcap: argv.coinmarketcap,
  113. };
  114. }
  115. if (argv.coverage) {
  116. require('solidity-coverage');
  117. module.exports.networks.hardhat.initialBaseFeePerGas = 0;
  118. }
  119. function hasFoundry() {
  120. return proc.spawnSync('forge', ['-V'], { stdio: 'ignore' }).error === undefined;
  121. }