-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ts
40 lines (35 loc) · 1.07 KB
/
helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Network } from "hardhat/types";
import { promises as fs } from "fs";
import path from "path";
import { format } from "prettier";
export const getDeploymentFileByName = async (
fileName: string,
network: Network
) => {
return JSON.parse(
await fs.readFile(
path.join(__dirname, `./deployments/${network.name}/${fileName}.json`),
"utf8"
)
);
};
// alternative to deployments.get() for implementations as it returns `undefined` if we had just modified the deployments json file.
export const setImplementation = async (
contractName: string,
network: Network
) => {
const contract = await getDeploymentFileByName(contractName, network);
const contractImplementation = await getDeploymentFileByName(
`${contractName}_Implementation`,
network
);
contract.implementation = contractImplementation.address;
await fs.writeFile(
path.join(__dirname, `./deployments/${network.name}/${contractName}.json`),
format(JSON.stringify(contract), {
semi: false,
parser: "json",
})
);
return contractImplementation.address;
};