@@ -27,16 +27,31 @@ export const getContract = async (
27
27
hre : HardhatRuntimeEnvironment ,
28
28
contractName : string ,
29
29
// keeping this param and not using deployments.get() because it helps to see the module's dependencies on other contracts
30
- contractAddress : string
30
+ // making optional for querying DefaultProxyAdmin
31
+ contractAddress ?: string
31
32
) => {
33
+ // this fails to read "DefaultProxyAdmin":
34
+ /**
32
35
const { deployments } = hre;
33
-
34
36
const artifact = await deployments.getArtifact(contractName);
35
37
const contractFactory = await hre.ethers.getContractFactory(
36
38
artifact.abi,
37
39
artifact.bytecode
38
40
);
39
41
const contract = contractFactory.attach(contractAddress);
42
+ */
43
+
44
+ const contractDeployment = await getDeploymentFileByName (
45
+ contractName ,
46
+ hre . network
47
+ ) ;
48
+ const contract = (
49
+ await hre . ethers . getContractFactory (
50
+ contractDeployment . abi ,
51
+ contractDeployment . bytecode
52
+ )
53
+ ) . attach ( contractAddress ?? contractDeployment . address ) ;
54
+
40
55
return contract ;
41
56
} ;
42
57
@@ -103,16 +118,7 @@ export const handleUpgradeDeploy = async ({
103
118
} ) : Promise < Deployment > => {
104
119
const { deploy, network, deployments } = await getConfig ( hre ) ;
105
120
106
- const defaultProxyAdminDeployment = await getDeploymentFileByName (
107
- "DefaultProxyAdmin" ,
108
- network
109
- ) ;
110
- const defaultProxyAdminContract = (
111
- await hre . ethers . getContractFactory (
112
- defaultProxyAdminDeployment . abi ,
113
- defaultProxyAdminDeployment . bytecode
114
- )
115
- ) . attach ( defaultProxyAdminDeployment . address ) ;
121
+ const defaultProxyAdminContract = await getContract ( hre , "DefaultProxyAdmin" ) ;
116
122
117
123
// set the current owner of the proxy, in the deployOptions
118
124
deployOptions . proxy = {
@@ -128,8 +134,6 @@ export const handleUpgradeDeploy = async ({
128
134
await setImplementation ( contractName , network ) ;
129
135
deployment = await deployments . get ( contractName ) ;
130
136
131
- console . log ( e ) ;
132
-
133
137
console . warn (
134
138
`[⚠️ NOTE!] call "upgrade" on DefaultProxyAdmin to upgrade the implementation for ${ contractName } `
135
139
) ;
0 commit comments