hardhat.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. mode: {
  24. alias: 'compileMode',
  25. type: 'string',
  26. choices: ['production', 'development'],
  27. default: 'development',
  28. },
  29. ir: {
  30. alias: 'enableIR',
  31. type: 'boolean',
  32. default: false,
  33. },
  34. foundry: {
  35. alias: 'hasFoundry',
  36. type: 'boolean',
  37. default: hasFoundry(),
  38. },
  39. compiler: {
  40. alias: 'compileVersion',
  41. type: 'string',
  42. default: '0.8.20',
  43. },
  44. coinmarketcap: {
  45. alias: 'coinmarketcapApiKey',
  46. type: 'string',
  47. },
  48. }).argv;
  49. require('@nomicfoundation/hardhat-chai-matchers');
  50. require('@nomicfoundation/hardhat-ethers');
  51. require('hardhat-exposed');
  52. require('hardhat-gas-reporter');
  53. require('hardhat-ignore-warnings');
  54. require('solidity-coverage');
  55. require('solidity-docgen');
  56. argv.foundry && require('@nomicfoundation/hardhat-foundry');
  57. if (argv.foundry && argv.coverage) {
  58. throw Error('Coverage analysis is incompatible with Foundry. Disable with `FOUNDRY=false` in the environment');
  59. }
  60. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  61. require(path.join(__dirname, 'hardhat', f));
  62. }
  63. const withOptimizations = argv.gas || argv.coverage || argv.compileMode === 'production';
  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: !withOptimizations,
  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. docgen: require('./docs/config'),
  108. };
  109. function hasFoundry() {
  110. return proc.spawnSync('forge', ['-V'], { stdio: 'ignore' }).error === undefined;
  111. }