|
| 1 | +import * as fs from "fs"; |
| 2 | +import { config as dotenvConfig } from "dotenv"; |
| 3 | +import "@nomiclabs/hardhat-ethers"; |
| 4 | +import '@typechain/hardhat' |
| 5 | +import '@nomiclabs/hardhat-ethers' |
| 6 | +import '@nomiclabs/hardhat-waffle' |
| 7 | +import { HardhatUserConfig } from "hardhat/config"; |
| 8 | +import "hardhat-gas-reporter"; |
| 9 | +import "hardhat-preprocessor"; |
| 10 | +import "solidity-coverage"; |
| 11 | + |
| 12 | +dotenvConfig(); |
| 13 | + |
| 14 | +// Ensure that we have all the environment variables we need. |
| 15 | +const mnemonic = process.env.MNEMONIC as string; |
| 16 | +const mainnetUrl = process.env.MAINNET_URL as string; |
| 17 | + |
| 18 | +const chainIds = { |
| 19 | + hardhat: 1337, |
| 20 | + mainnet: 1, |
| 21 | + "polygon-mainnet": 137, |
| 22 | + rinkeby: 4, |
| 23 | +}; |
| 24 | + |
| 25 | +function getRemappings() { |
| 26 | + return fs |
| 27 | + .readFileSync("remappings.txt", "utf8") |
| 28 | + .split("\n") |
| 29 | + .map((line) => line.trim().split("=")); |
| 30 | +} |
| 31 | + |
| 32 | +const config: HardhatUserConfig = { |
| 33 | + defaultNetwork: "hardhat", |
| 34 | + gasReporter: { |
| 35 | + currency: "USD", |
| 36 | + enabled: true, |
| 37 | + excludeContracts: [], |
| 38 | + src: "./contracts", |
| 39 | + }, |
| 40 | + networks: { |
| 41 | + hardhat: { |
| 42 | + gas: "auto", |
| 43 | + accounts: { |
| 44 | + mnemonic, |
| 45 | + }, |
| 46 | + chainId: chainIds.hardhat, |
| 47 | + // forking: { |
| 48 | + // url: mainnetUrl, |
| 49 | + // blockNumber: Number.parseInt(process.env.DEFAULT_FORK_BLOCK as string), |
| 50 | + // }, |
| 51 | + }, |
| 52 | + // mainnet: { |
| 53 | + // accounts: [process.env.PRIVATE_KEY as string], |
| 54 | + // chainId: chainIds.mainnet, |
| 55 | + // url: mainnetUrl, |
| 56 | + // }, |
| 57 | + // "polygon-mainnet": { |
| 58 | + // accounts: [process.env.PRIVATE_KEY as string], |
| 59 | + // chainId: chainIds["polygon-mainnet"], |
| 60 | + // url: process.env.POLYGON_MAINNET_URL, |
| 61 | + // timeout: 100000, |
| 62 | + // }, |
| 63 | + // rinkeby: { |
| 64 | + // accounts: { |
| 65 | + // mnemonic |
| 66 | + // }, |
| 67 | + // chainId: chainIds.rinkeby, |
| 68 | + // url: process.env.RINKEBY_URL, |
| 69 | + // }, |
| 70 | + }, |
| 71 | + paths: { |
| 72 | + artifacts: "./artifacts", |
| 73 | + cache: "./cache", |
| 74 | + sources: "./src", |
| 75 | + tests: "./src/test", |
| 76 | + }, |
| 77 | + solidity: { |
| 78 | + compilers: [ |
| 79 | + { |
| 80 | + version: "0.8.15", |
| 81 | + settings: { |
| 82 | + // viaIR: true, |
| 83 | + metadata: { |
| 84 | + // Not including the metadata hash |
| 85 | + // https://github.com/paulrberg/solidity-template/issues/31 |
| 86 | + bytecodeHash: "none", |
| 87 | + }, |
| 88 | + // Disable the optimizer when debugging |
| 89 | + // https://hardhat.org/hardhat-network/#solidity-optimizer-support |
| 90 | + optimizer: { |
| 91 | + enabled: true, |
| 92 | + runs: 200, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + typechain: { |
| 99 | + outDir: "./typechain/types", |
| 100 | + target: "ethers-v5", |
| 101 | + }, |
| 102 | + preprocess: { |
| 103 | + eachLine: (hre) => ({ |
| 104 | + transform: (line: string) => { |
| 105 | + if (line.match(/^\s*import /i)) { |
| 106 | + getRemappings().forEach(([find, replace]) => { |
| 107 | + if (line.match('"' + find)) { |
| 108 | + line = line.replace('"' + find, '"' + replace); |
| 109 | + } |
| 110 | + }); |
| 111 | + } |
| 112 | + return line; |
| 113 | + }, |
| 114 | + }), |
| 115 | + }, |
| 116 | +}; |
| 117 | + |
| 118 | +export default config; |
0 commit comments