hardhat.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. })
  49. .argv;
  50. require('@nomiclabs/hardhat-truffle5');
  51. require('hardhat-ignore-warnings');
  52. require('solidity-docgen');
  53. if (argv.gas) {
  54. require('hardhat-gas-reporter');
  55. }
  56. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  57. require(path.join(__dirname, 'hardhat', f));
  58. }
  59. const withOptimizations = argv.gas || argv.compileMode === 'production';
  60. /**
  61. * @type import('hardhat/config').HardhatUserConfig
  62. */
  63. module.exports = {
  64. solidity: {
  65. version: argv.compiler,
  66. settings: {
  67. optimizer: {
  68. enabled: withOptimizations,
  69. runs: 200,
  70. },
  71. viaIR: withOptimizations && argv.ir,
  72. },
  73. },
  74. warnings: {
  75. '*': {
  76. 'code-size': withOptimizations,
  77. 'unused-param': !argv.coverage, // coverage causes unused-param warnings
  78. default: 'error',
  79. },
  80. },
  81. networks: {
  82. hardhat: {
  83. blockGasLimit: 10000000,
  84. allowUnlimitedContractSize: !withOptimizations,
  85. },
  86. },
  87. gasReporter: {
  88. showMethodSig: true,
  89. currency: 'USD',
  90. outputFile: argv.gasReport,
  91. coinmarketcap: argv.coinmarketcap,
  92. },
  93. docgen: require('./docs/config'),
  94. };
  95. if (argv.coverage) {
  96. require('solidity-coverage');
  97. module.exports.networks.hardhat.initialBaseFeePerGas = 0;
  98. }