hardhat.config.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. ci: {
  14. type: 'boolean',
  15. default: false,
  16. },
  17. coverage: {
  18. type: 'boolean',
  19. default: false,
  20. },
  21. gas: {
  22. alias: 'enableGasReport',
  23. type: 'boolean',
  24. default: false,
  25. },
  26. mode: {
  27. alias: 'compileMode',
  28. type: 'string',
  29. choices: [ 'production', 'development' ],
  30. default: 'development',
  31. },
  32. compiler: {
  33. alias: 'compileVersion',
  34. type: 'string',
  35. default: '0.8.9',
  36. },
  37. coinmarketcap: {
  38. alias: 'coinmarketcapApiKey',
  39. type: 'string',
  40. },
  41. })
  42. .argv;
  43. require('@nomiclabs/hardhat-truffle5');
  44. if (argv.enableGasReport) {
  45. require('hardhat-gas-reporter');
  46. }
  47. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  48. require(path.join(__dirname, 'hardhat', f));
  49. }
  50. const withOptimizations = argv.enableGasReport || argv.compileMode === 'production';
  51. /**
  52. * @type import('hardhat/config').HardhatUserConfig
  53. */
  54. module.exports = {
  55. solidity: {
  56. version: argv.compiler,
  57. settings: {
  58. optimizer: {
  59. enabled: withOptimizations,
  60. runs: 200,
  61. },
  62. },
  63. },
  64. networks: {
  65. hardhat: {
  66. blockGasLimit: 10000000,
  67. allowUnlimitedContractSize: !withOptimizations,
  68. },
  69. },
  70. gasReporter: {
  71. currency: 'USD',
  72. outputFile: argv.ci ? 'gas-report.txt' : undefined,
  73. coinmarketcap: argv.coinmarketcap,
  74. },
  75. };
  76. if (argv.coverage) {
  77. require('solidity-coverage');
  78. module.exports.networks.hardhat.initialBaseFeePerGas = 0;
  79. }