hardhat.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.9)
  7. // - COINMARKETCAP: coinmarkercat api key for USD value in gas report
  8. const fs = require('fs');
  9. const path = require('path');
  10. const argv = require('yargs/yargs')()
  11. .env('')
  12. .options({
  13. coverage: {
  14. type: 'boolean',
  15. default: false,
  16. },
  17. gas: {
  18. alias: 'enableGasReport',
  19. type: 'boolean',
  20. default: false,
  21. },
  22. gasReport: {
  23. alias: 'enableGasReportPath',
  24. type: 'string',
  25. implies: 'gas',
  26. default: undefined,
  27. },
  28. mode: {
  29. alias: 'compileMode',
  30. type: 'string',
  31. choices: ['production', 'development'],
  32. default: 'development',
  33. },
  34. ir: {
  35. alias: 'enableIR',
  36. type: 'boolean',
  37. default: false,
  38. },
  39. compiler: {
  40. alias: 'compileVersion',
  41. type: 'string',
  42. default: '0.8.13',
  43. },
  44. coinmarketcap: {
  45. alias: 'coinmarketcapApiKey',
  46. type: 'string',
  47. },
  48. }).argv;
  49. require('@nomiclabs/hardhat-truffle5');
  50. require('hardhat-ignore-warnings');
  51. require('hardhat-exposed');
  52. require('solidity-docgen');
  53. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  54. require(path.join(__dirname, 'hardhat', f));
  55. }
  56. const withOptimizations = argv.gas || argv.compileMode === 'production';
  57. /**
  58. * @type import('hardhat/config').HardhatUserConfig
  59. */
  60. module.exports = {
  61. solidity: {
  62. version: argv.compiler,
  63. settings: {
  64. optimizer: {
  65. enabled: withOptimizations,
  66. runs: 200,
  67. },
  68. viaIR: withOptimizations && argv.ir,
  69. outputSelection: { '*': { '*': ['storageLayout'] } },
  70. },
  71. },
  72. warnings: {
  73. '*': {
  74. 'code-size': withOptimizations,
  75. 'unused-param': !argv.coverage, // coverage causes unused-param warnings
  76. default: 'error',
  77. },
  78. },
  79. networks: {
  80. hardhat: {
  81. blockGasLimit: 10000000,
  82. allowUnlimitedContractSize: !withOptimizations,
  83. },
  84. },
  85. exposed: {
  86. initializers: true,
  87. exclude: [
  88. 'vendor/**/*',
  89. // Exclude Timers from hardhat-exposed because its overloaded functions are not transformed correctly
  90. 'utils/Timers{,Upgradeable}.sol',
  91. ],
  92. },
  93. docgen: require('./docs/config'),
  94. };
  95. if (argv.gas) {
  96. require('hardhat-gas-reporter');
  97. module.exports.gasReporter = {
  98. showMethodSig: true,
  99. currency: 'USD',
  100. outputFile: argv.gasReport,
  101. coinmarketcap: argv.coinmarketcap,
  102. };
  103. }
  104. if (argv.coverage) {
  105. require('solidity-coverage');
  106. module.exports.networks.hardhat.initialBaseFeePerGas = 0;
  107. }