Skip to content

Commit b654195

Browse files
authored
Stop importing hardhat in lib link generation utils (#68)
* Stop importing hardhat in lib link generation utils * Update version to 0.0.25
1 parent f3d1c6c commit b654195

File tree

3 files changed

+12
-47
lines changed

3 files changed

+12
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@setprotocol/index-coop-contracts",
3-
"version": "0.0.22",
3+
"version": "0.0.25",
44
"description": "",
55
"main": "dist",
66
"types": "dist/types",

utils/common/libraryUtils.ts

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,16 @@
11
import { utils } from "ethers";
2-
import { artifacts } from "hardhat";
3-
import { Artifact } from "hardhat/types";
42
import path from "path";
5-
import globby from "globby";
63

7-
// If libraryName corresponds to more than one artifact (e.g there are
8-
// duplicate contract names in the project), `readArtifactSync`
9-
// will throw. In such cases it"s necessary to pass this method the fully qualified
10-
// contract name. ex: `contracts/mocks/LibraryMock.sol:LibraryMock`
4+
// Converts a fully qualified contract name in a bytecode link id.
5+
// (A fully qualified name looks like: `contracts/mocks/LibraryMock.sol:LibraryMock`)
116
export function convertLibraryNameToLinkId(libraryName: string): string {
12-
let artifact;
13-
let fullyQualifiedName;
14-
15-
if (libraryName.includes(path.sep) && libraryName.includes(":")) {
16-
fullyQualifiedName = libraryName;
17-
} else {
18-
artifact = getArtifact(libraryName);
19-
fullyQualifiedName = `${artifact.sourceName}:${artifact.contractName}`;
20-
}
21-
22-
const hashedName = utils.keccak256(utils.toUtf8Bytes(fullyQualifiedName));
23-
return `__$${hashedName.slice(2).slice(0, 34)}$__`;
24-
}
25-
26-
// Tries to resolve via hardhat artifacts helpers, then by searching for appropriately
27-
// named jsons in the root `external` folder
28-
function getArtifact(libraryName: string): Artifact {
29-
try {
30-
return artifacts.readArtifactSync(libraryName);
31-
} catch (e) {
32-
/* ignore */
33-
}
34-
35-
const files = globby.sync("external", {
36-
expandDirectories: { extensions: ["json"], },
37-
});
38-
39-
const matches = files.filter(f => f.includes(`/${libraryName}.json`));
40-
41-
if (!matches.length) {
42-
throw new Error(`Unable to find artifact for '${libraryName}' while linking.`);
43-
}
44-
45-
if (matches.length > 1) {
7+
if (!(libraryName.includes(path.sep) && libraryName.includes(":"))) {
468
throw new Error(
47-
`Unable to resolve '${libraryName}' while linking. ` +
48-
`(More than one file name matches in 'external/')`
9+
"Converting library name to link id requires a fully qualified " +
10+
"contract name. Example: `contracts/mocks/LibraryMock.sol:LibraryMock`"
4911
);
5012
}
5113

52-
const pathToArtifact = path.join(process.cwd(), matches[0]);
53-
return require(pathToArtifact);
14+
const hashedName = utils.keccak256(utils.toUtf8Bytes(libraryName));
15+
return `__$${hashedName.slice(2).slice(0, 34)}$__`;
5416
}

utils/deploys/deploySetV2.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ export default class DeploySetV2 {
148148
weth: Address,
149149
): Promise<CompoundLeverageModule> {
150150
const compoundLib = await this.deployCompoundLib();
151-
const linkId = convertLibraryNameToLinkId("Compound");
151+
152+
const linkId = convertLibraryNameToLinkId(
153+
"contracts/protocol/integration/lib/Compound.sol:Compound"
154+
);
152155

153156
return await new CompoundLeverageModule__factory(
154157
// @ts-ignore

0 commit comments

Comments
 (0)