hardhat.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /// ENVVAR
  2. // - COMPILER: compiler version (default: 0.8.27)
  3. // - SRC: contracts folder to compile (default: contracts)
  4. // - RUNS: number of optimization runs (default: 200)
  5. // - IR: enable IR compilation (default: false)
  6. // - COVERAGE: enable coverage report (default: false)
  7. // - GAS: enable gas report (default: false)
  8. // - COINMARKETCAP: coinmarketcap 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.27',
  20. },
  21. src: {
  22. alias: 'source',
  23. type: 'string',
  24. default: 'contracts',
  25. },
  26. runs: {
  27. alias: 'optimizationRuns',
  28. type: 'number',
  29. default: 200,
  30. },
  31. ir: {
  32. alias: 'enableIR',
  33. type: 'boolean',
  34. default: false,
  35. },
  36. evm: {
  37. alias: 'evmVersion',
  38. type: 'string',
  39. default: 'prague',
  40. },
  41. // Extra modules
  42. coverage: {
  43. type: 'boolean',
  44. default: false,
  45. },
  46. gas: {
  47. alias: 'enableGasReport',
  48. type: 'boolean',
  49. default: false,
  50. },
  51. coinmarketcap: {
  52. alias: 'coinmarketcapApiKey',
  53. type: 'string',
  54. },
  55. });
  56. require('@nomicfoundation/hardhat-chai-matchers');
  57. require('@nomicfoundation/hardhat-ethers');
  58. require('hardhat-exposed');
  59. require('hardhat-gas-reporter');
  60. require('hardhat-ignore-warnings');
  61. require('hardhat-predeploy');
  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. /**
  68. * @type import('hardhat/config').HardhatUserConfig
  69. */
  70. module.exports = {
  71. solidity: {
  72. version: argv.compiler,
  73. settings: {
  74. optimizer: {
  75. enabled: true,
  76. runs: argv.runs,
  77. },
  78. evmVersion: argv.evm,
  79. viaIR: argv.ir,
  80. outputSelection: { '*': { '*': ['storageLayout'] } },
  81. },
  82. },
  83. warnings: {
  84. 'contracts-exposed/**/*': {
  85. 'code-size': 'off',
  86. 'initcode-size': 'off',
  87. },
  88. '*': {
  89. 'unused-param': !argv.coverage, // coverage causes unused-param warnings
  90. 'transient-storage': false,
  91. default: 'error',
  92. },
  93. },
  94. networks: {
  95. hardhat: {
  96. hardfork: argv.evm,
  97. // Exposed contracts often exceed the maximum contract size. For normal contract,
  98. // we rely on the `code-size` compiler warning, that will cause a compilation error.
  99. allowUnlimitedContractSize: true,
  100. initialBaseFeePerGas: argv.coverage ? 0 : undefined,
  101. enableRip7212: true,
  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. };