hardhat/types#HardhatConfig TypeScript Examples

The following examples show how to use hardhat/types#HardhatConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From openzeppelin-upgrades with MIT License 6 votes vote down vote up
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
  if (!userConfig.defender || !userConfig.defender.apiKey || !userConfig.defender.apiSecret) {
    const sampleConfig = JSON.stringify({ apiKey: 'YOUR_API_KEY', apiSecret: 'YOUR_API_SECRET' }, null, 2);
    console.warn(
      `Defender API key and secret are not set. Add the following to your hardhat.config.js exported configuration:\n\n${sampleConfig}\n`,
    );
  }
  config.defender = userConfig.defender;
});
Example #2
Source File: index.ts    From openzeppelin-upgrades with MIT License 6 votes vote down vote up
extendConfig((config: HardhatConfig) => {
  for (const compiler of config.solidity.compilers) {
    compiler.settings ??= {};
    compiler.settings.outputSelection ??= {};
    compiler.settings.outputSelection['*'] ??= {};
    compiler.settings.outputSelection['*']['*'] ??= [];

    if (!compiler.settings.outputSelection['*']['*'].includes('storageLayout')) {
      compiler.settings.outputSelection['*']['*'].push('storageLayout');
    }
  }
});
Example #3
Source File: index.ts    From hardhat-kms-signer with MIT License 6 votes vote down vote up
extendConfig(
  (config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
    const userNetworks = userConfig.networks;
    if (userNetworks === undefined) {
      return;
    }
    for (const networkName in userNetworks) {
      if (networkName === "hardhat") {
        continue;
      }
      const network = userNetworks[networkName]!;
      if (network.kmsKeyId) {
        config.networks[networkName].kmsKeyId = network.kmsKeyId;
      }
    }
  }
);
Example #4
Source File: index.ts    From hardhat-deploy with MIT License 6 votes vote down vote up
function normalizePathArray(config: HardhatConfig, paths: string[]): string[] {
  const newArray: string[] = [];
  for (const value of paths) {
    if (value) {
      newArray.push(normalizePath(config, value, value));
    }
  }
  return newArray;
}
Example #5
Source File: index.ts    From hardhat-deploy with MIT License 6 votes vote down vote up
function normalizePath(
  config: HardhatConfig,
  userPath: string | undefined,
  defaultPath: string
): string {
  if (userPath === undefined) {
    userPath = path.join(config.paths.root, defaultPath);
  } else {
    if (!path.isAbsolute(userPath)) {
      userPath = path.normalize(path.join(config.paths.root, userPath));
    }
  }
  return userPath;
}
Example #6
Source File: index.ts    From hardhat-circom with GNU General Public License v3.0 5 votes vote down vote up
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
  const { root } = config.paths;

  const { inputBasePath, outputBasePath, ptau, circuits = [] } = userConfig.circom ?? {};

  if (circuits.length === 0) {
    throw new HardhatPluginError(
      PLUGIN_NAME,
      "Missing required circuits list, please provide via hardhat.config.js (circom.circuits) a list of circuit names to load from the inputBasePath"
    );
  }
  if (!ptau) {
    throw new HardhatPluginError(
      PLUGIN_NAME,
      "Missing required ptau location, please provide via hardhat.config.js (circom.ptau) the location of your ptau file"
    );
  }

  const defaultInputBasePath = path.join(root, "circuits");
  const defaultOutputBasePath = path.join(root, "circuits");

  const normalizedInputBasePath = normalize(root, inputBasePath) ?? defaultInputBasePath;
  const normalizedOutputBasePath = normalize(root, outputBasePath) ?? defaultOutputBasePath;

  const normalizedPtauPath = path.resolve(normalizedInputBasePath, ptau);

  config.circom = {
    inputBasePath: normalizedInputBasePath,
    outputBasePath: normalizedOutputBasePath,
    ptau: normalizedPtauPath,
    circuits: [],
  };

  for (const { name, version, protocol, beacon, circuit, input, wasm, r1cs, zkey, vkey } of circuits) {
    if (!name) {
      throw new HardhatPluginError(
        PLUGIN_NAME,
        "Missing required name field in circuits list, please provide via hardhat.config.js (circom.circuits.name)"
      );
    }

    const circuitPath = path.resolve(normalizedInputBasePath, circuit ?? `${name}.circom`);
    const inputPath = path.resolve(normalizedInputBasePath, input ?? `${name}.json`);
    const wasmPath = path.resolve(normalizedOutputBasePath, wasm ?? `${name}.wasm`);
    const r1csPath = path.resolve(normalizedOutputBasePath, r1cs ?? `${name}.r1cs`);
    const zkeyPath = path.resolve(normalizedOutputBasePath, zkey ?? `${name}.zkey`);
    const vkeyPath = path.resolve(normalizedOutputBasePath, vkey ?? `${name}.vkey.json`);

    config.circom.circuits.push({
      name: name,
      version: version !== 1 ? 2 : 1,
      protocol: protocol !== "plonk" ? "groth16" : "plonk",
      beacon: beacon != null ? beacon : "0000000000000000000000000000000000000000000000000000000000000000",
      circuit: circuitPath,
      input: inputPath,
      wasm: wasmPath,
      r1cs: r1csPath,
      zkey: zkeyPath,
      vkey: vkeyPath,
    });
  }
});
Example #7
Source File: index.ts    From hardhat-tenderly with GNU General Public License v3.0 4 votes vote down vote up
extractContractData = async (
  contracts: string[],
  network: string | undefined,
  config: HardhatConfig,
  run: RunTaskFunction
): Promise<TenderlyContract[]> => {
  let contract: string;
  const requestContracts: TenderlyContract[] = [];

  const sourcePaths = await run("compile:solidity:get-source-paths");
  const sourceNames = await run("compile:solidity:get-source-names", {
    sourcePaths
  });
  const data = await run("compile:solidity:get-dependency-graph", {
    sourceNames
  });

  const metadata: Metadata = {
    compiler: {
      version: config.solidity.compilers[0].version
    },
    sources: {}
  };

  data._resolvedFiles.forEach((resolvedFile, _) => {
    for (contract of contracts) {
      const contractData = contract.split("=");
      if (contractData.length < 2) {
        throw new HardhatPluginError(PluginName, `Invalid contract provided`);
      }

      if (network === undefined) {
        throw new HardhatPluginError(PluginName, `No network provided`);
      }
      const sourcePath: string = resolvedFile.sourceName;
      const name = sourcePath
        .split("/")
        .slice(-1)[0]
        .split(".")[0];

      if (name !== contractData[0]) {
        continue;
      }
      metadata.sources[sourcePath] = {
        content: resolvedFile.content.rawContent
      };
      const visited: Record<string, boolean> = {};
      resolveDependencies(data, sourcePath, metadata, visited);
    }
  });

  for (const [key, value] of Object.entries(metadata.sources)) {
    const name = key
      .split("/")
      .slice(-1)[0]
      .split(".")[0];

    const contractToPush: TenderlyContract = {
      contractName: name,
      source: value.content,
      sourcePath: key,
      networks: {},
      compiler: {
        name: "solc",
        version: config.solidity.compilers[0].version
      }
    };

    for (contract of contracts) {
      const contractData = contract.split("=");
      if (contractToPush.contractName === contractData[0]) {
        let chainID: string = NetworkMap[network!.toLowerCase()];
        if (config.networks[network!].chainId !== undefined) {
          chainID = config.networks[network!].chainId!.toString();
        }
        if (chainID === undefined) {
          console.log(
            `Error in ${PluginName}: Couldn't identify network. Please provide a chainID in the network config object`
          );
          return [];
        }
        contractToPush.networks = {
          [chainID]: {
            address: contractData[1]
          }
        };
      }
    }
    requestContracts.push(contractToPush);
  }
  return requestContracts;
}
Example #8
Source File: index.ts    From hardhat-deploy with MIT License 4 votes vote down vote up
extendConfig(
  (config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
    config.paths.deployments = normalizePath(
      config,
      userConfig.paths?.deployments,
      'deployments'
    );

    config.paths.imports = normalizePath(
      config,
      userConfig.paths?.imports,
      'imports'
    );

    if (userConfig.paths?.deploy) {
      let deployPaths = [];
      if (typeof userConfig.paths.deploy === 'string') {
        deployPaths = [userConfig.paths.deploy];
      } else {
        deployPaths = userConfig.paths.deploy;
      }
      config.paths.deploy = deployPaths.map((p) =>
        normalizePath(config, p, 'deploy')
      );
    } else {
      config.paths.deploy = [normalizePath(config, undefined, 'deploy')];
    }

    if (userConfig.namedAccounts) {
      config.namedAccounts = userConfig.namedAccounts;
    } else {
      config.namedAccounts = {};
    }

    config.deterministicDeployment = userConfig.deterministicDeployment;

    if (userConfig.external) {
      if (!config.external) {
        config.external = {};
      }
      if (userConfig.external.contracts) {
        const externalContracts: {artifacts: string[]; deploy?: string}[] = [];
        config.external.contracts = externalContracts;
        for (const userDefinedExternalContracts of userConfig.external
          .contracts) {
          const userArtifacts =
            typeof userDefinedExternalContracts.artifacts === 'string'
              ? [userDefinedExternalContracts.artifacts]
              : userDefinedExternalContracts.artifacts;
          externalContracts.push({
            artifacts: userArtifacts.map((v) => normalizePath(config, v, v)),
            deploy: userDefinedExternalContracts.deploy
              ? normalizePath(
                  config,
                  userDefinedExternalContracts.deploy,
                  userDefinedExternalContracts.deploy
                )
              : undefined,
          });
        }
      }
      if (userConfig.external.deployments) {
        config.external.deployments = {};
        for (const key of Object.keys(userConfig.external.deployments)) {
          config.external.deployments[key] = normalizePathArray(
            config,
            userConfig.external.deployments[key]
          );
        }
      }
    }

    for (const compiler of config.solidity.compilers) {
      setupExtraSolcSettings(compiler.settings);
    }

    const defaultConfig = {};
    if (userConfig.verify !== undefined) {
      const customConfig = userConfig.verify;
      config.verify = {...defaultConfig, ...customConfig};
    } else {
      config.verify = defaultConfig;
      // backward compatibility for runtime (js)
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      if ((userConfig as any).etherscan) {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        config.verify.etherscan = (userConfig as any).etherscan;
      }
    }
  }
);