hardhat.config.js 2.1 KB

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