hardhat.config.js 2.3 KB

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