hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
90 lines (87 loc) • 3.31 kB
JavaScript
import { getPrefixedHexString } from "@nomicfoundation/hardhat-utils/hex";
export function getContractArtifact(buildInfoId, userSourceName, inputSourceName, contractName, contract) {
const evmBytecode = contract.evm?.bytecode;
const bytecode = evmBytecode?.object !== undefined
? getPrefixedHexString(evmBytecode.object)
: "";
const evmDeployedBytecode = contract.evm?.deployedBytecode;
const deployedBytecode = evmDeployedBytecode?.object !== undefined
? getPrefixedHexString(evmDeployedBytecode.object)
: "";
const linkReferences = evmBytecode?.linkReferences ?? {};
const deployedLinkReferences = evmDeployedBytecode?.linkReferences ?? {};
const immutableReferences = evmDeployedBytecode?.immutableReferences ?? {};
const artifact = {
_format: "hh3-artifact-1",
contractName,
sourceName: userSourceName,
abi: contract.abi,
bytecode,
deployedBytecode,
linkReferences,
deployedLinkReferences,
immutableReferences,
inputSourceName,
buildInfoId,
};
return artifact;
}
export function getArtifactsDeclarationFile(artifacts) {
if (artifacts.length === 0) {
return "";
}
const artifactTypes = artifacts.map((artifact) => `export interface ${artifact.contractName}$Type {
${Object.entries(artifact)
.map(([name, value]) => `readonly ${name}: ${JSON.stringify(value)};`)
.join("\n ")}
};`);
return `// This file was autogenerated by Hardhat, do not edit it.
// prettier-ignore
// tslint:disable
// eslint-disable
// biome-ignore format: see above
${artifactTypes.join("\n\n")}
import "hardhat/types/artifacts";
declare module "hardhat/types/artifacts" {
interface ArtifactMap {
${artifacts.map((artifact) => `["${artifact.contractName}"]: ${artifact.contractName}$Type`).join("\n ")};
${artifacts.map((artifact) => `["${artifact.sourceName}:${artifact.contractName}"]: ${artifact.contractName}$Type`).join("\n ")};
}
}`;
}
export function getDuplicatedContractNamesDeclarationFile(duplicatedContractNames) {
if (duplicatedContractNames.length === 0) {
return "";
}
return `// This file was autogenerated by Hardhat, do not edit it.
// prettier-ignore
// tslint:disable
// eslint-disable
// biome-ignore format: see above
import "hardhat/types/artifacts";
declare module "hardhat/types/artifacts" {
interface ArtifactMap {
${duplicatedContractNames.map((name) => `["${name}"]: never`).join("\n ")};
}
}`;
}
export async function getBuildInfo(compilationJob) {
const buildInfo = {
_format: "hh3-sol-build-info-1",
id: await compilationJob.getBuildId(),
solcVersion: compilationJob.solcConfig.version,
solcLongVersion: compilationJob.solcLongVersion,
userSourceNameMap: compilationJob.dependencyGraph.getRootsUserSourceNameMap(),
input: await compilationJob.getSolcInput(),
};
return buildInfo;
}
export async function getBuildInfoOutput(compilationJob, compilerOutput) {
const buildInfoOutput = {
_format: "hh3-sol-build-info-output-1",
id: await compilationJob.getBuildId(),
output: compilerOutput,
};
return buildInfoOutput;
}
//# sourceMappingURL=artifacts.js.map