hardhat.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ir: {
  33. alias: 'enableIR',
  34. type: 'boolean',
  35. default: false,
  36. },
  37. compiler: {
  38. alias: 'compileVersion',
  39. type: 'string',
  40. default: '0.8.13',
  41. },
  42. coinmarketcap: {
  43. alias: 'coinmarketcapApiKey',
  44. type: 'string',
  45. },
  46. })
  47. .argv;
  48. require('@nomiclabs/hardhat-truffle5');
  49. if (argv.enableGasReport) {
  50. require('hardhat-gas-reporter');
  51. }
  52. for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
  53. require(path.join(__dirname, 'hardhat', f));
  54. }
  55. const withOptimizations = argv.enableGasReport || argv.compileMode === 'production';
  56. /**
  57. * @type import('hardhat/config').HardhatUserConfig
  58. */
  59. module.exports = {
  60. solidity: {
  61. version: argv.compiler,
  62. settings: {
  63. optimizer: {
  64. enabled: withOptimizations,
  65. runs: 200,
  66. },
  67. viaIR: withOptimizations && argv.ir,
  68. },
  69. },
  70. networks: {
  71. hardhat: {
  72. blockGasLimit: 10000000,
  73. allowUnlimitedContractSize: !withOptimizations,
  74. },
  75. },
  76. gasReporter: {
  77. currency: 'USD',
  78. outputFile: argv.ci ? 'gas-report.txt' : undefined,
  79. coinmarketcap: argv.coinmarketcap,
  80. },
  81. };
  82. if (argv.coverage) {
  83. require('solidity-coverage');
  84. module.exports.networks.hardhat.initialBaseFeePerGas = 0;
  85. }