hardhat.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  61. require(path.join(__dirname, 'hardhat', f));
  62. }
  63. const withOptimizations = argv.gas || 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. blockGasLimit: 10000000,
  93. allowUnlimitedContractSize: !withOptimizations,
  94. },
  95. },
  96. exposed: {
  97. imports: true,
  98. initializers: true,
  99. exclude: ['vendor/**/*'],
  100. },
  101. docgen: require('./docs/config'),
  102. };
  103. if (argv.gas) {
  104. require('hardhat-gas-reporter');
  105. module.exports.gasReporter = {
  106. showMethodSig: true,
  107. currency: 'USD',
  108. outputFile: argv.gasReport,
  109. coinmarketcap: argv.coinmarketcap,
  110. };
  111. }
  112. if (argv.coverage) {
  113. require('solidity-coverage');
  114. module.exports.networks.hardhat.initialBaseFeePerGas = 0;
  115. }
  116. function hasFoundry() {
  117. return proc.spawnSync('forge', ['-V'], { stdio: 'ignore' }).error === undefined;
  118. }