Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing library references in Zodiac Core mastercopy JSON #18

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/artifact/writeMastercopyFromBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function writeMastercopyFromBuild({
compilerInput?: any;
buildDirPath?: string;
mastercopyArtifactsFile?: string;
}) {
}): MastercopyArtifact {
const buildArtifact = getBuildArtifact(contractName, buildDirPath);

const mastercopies = existsSync(mastercopyArtifactsFile)
Expand All @@ -66,6 +66,23 @@ export default function writeMastercopyFromBuild({
mastercopies
);

const compilerInput = minimalCompilerInput || buildArtifact.compilerInput;
compilerInput.settings = compilerInput.settings || {};
compilerInput.settings.libraries = compilerInput.settings.libraries || {};
for (const libraryPath of Object.keys(buildArtifact.linkReferences)) {
compilerInput.settings.libraries[libraryPath] =
compilerInput.settings.libraries[libraryPath] || {};
for (const libraryName of Object.keys(
buildArtifact.linkReferences[libraryPath]
)) {
const libraryAddress =
mastercopies[libraryName]?.[contractVersion]?.address;
if (libraryAddress) {
compilerInput.settings.libraries[libraryPath][libraryName] =
libraryAddress;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}
}
const mastercopyArtifact: MastercopyArtifact = {
contractName,
sourceName: buildArtifact.sourceName,
Expand All @@ -82,7 +99,7 @@ export default function writeMastercopyFromBuild({
constructorArgs,
salt,
abi: buildArtifact.abi,
compilerInput: minimalCompilerInput || buildArtifact.compilerInput,
compilerInput,
};

const nextMastercopies = {
Expand Down Expand Up @@ -111,4 +128,6 @@ export default function writeMastercopyFromBuild({
JSON.stringify(sortedMastercopies, null, 2),
"utf8"
);

return mastercopyArtifact;
}
2 changes: 2 additions & 0 deletions src/artifact/writeMastercopyFromExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ export default async function writeMastercopyFromExplorer({
JSON.stringify(sortedMastercopies, null, 2),
"utf8"
);

return mastercopyArtifact;
}
Loading