-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
96 lines (86 loc) · 2.39 KB
/
utils.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { getImplementationAddress } from '@openzeppelin/upgrades-core';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
export const getImplAddressFromProxy = async (
hre: HardhatRuntimeEnvironment,
proxyAddress: string,
): Promise<string> =>
await getImplementationAddress(hre.ethers.provider, proxyAddress);
export const logDeploy = (
contractName: string,
contractType: string | undefined,
address: string,
) =>
console.info(
`\x1b[32m${contractName}\x1b[0m${contractType ? ' ' : ''}${
contractType ?? ''
}:\t`,
'\x1b[36m',
address,
'\x1b[0m',
);
export const etherscanVerify = async (
hre: HardhatRuntimeEnvironment,
contractAddress: string,
...constructorArguments: unknown[]
) => {
const network = hre.network.name;
if (network === 'localhost' || network === 'hardhat') return;
await verify(hre, contractAddress, ...constructorArguments);
};
export const etherscanVerifyImplementation = async (
hre: HardhatRuntimeEnvironment,
proxyAddress: string,
...constructorArguments: unknown[]
) => {
const contractAddress = await getImplAddressFromProxy(hre, proxyAddress);
return etherscanVerify(hre, contractAddress, ...constructorArguments);
};
export const logDeployProxy = async (
hre: HardhatRuntimeEnvironment,
contractName: string,
address: string,
) => {
logDeploy(contractName, 'Proxy', address);
try {
logDeploy(
contractName,
'Impl',
await getImplAddressFromProxy(hre, address),
);
} catch (err) {
console.error('Log impl error. ', err);
}
};
export const tryEtherscanVerifyImplementation = async (
hre: HardhatRuntimeEnvironment,
proxyAddress: string,
...constructorArguments: unknown[]
) => {
return await etherscanVerifyImplementation(
hre,
proxyAddress,
...constructorArguments,
)
.catch((err) => {
console.error('Unable to verify. Error: ', err);
return false;
})
.then(() => {
return true;
});
};
export const verify = async (
hre: HardhatRuntimeEnvironment,
contractAddress: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...constructorArguments: any[]
) => {
console.log('Arguments: ', constructorArguments);
await hre.run('verify:verify', {
address: contractAddress,
constructorArguments,
});
};