@@ -106,6 +106,32 @@ async function checkImplementationArtifacts(
106106 }
107107}
108108
109+ // Helper to perform a standard upgrade: compile, check artifacts, load address, upgrade
110+ async function upgradeContract (
111+ contractName : string ,
112+ addressEnvVar : string ,
113+ taskArgs : TaskArguments ,
114+ hre : HardhatRuntimeEnvironment ,
115+ reinitializeArgs : unknown [ ] = [ ] ,
116+ ) {
117+ await compileImplementations ( taskArgs . currentImplementation , taskArgs . newImplementation , hre ) ;
118+ await checkImplementationArtifacts ( contractName , taskArgs . currentImplementation , taskArgs . newImplementation , hre ) ;
119+
120+ if ( taskArgs . useInternalProxyAddress ) {
121+ loadGatewayAddresses ( ) ;
122+ }
123+ const proxyAddress = getRequiredEnvVar ( addressEnvVar ) ;
124+
125+ await upgradeCurrentToNew (
126+ proxyAddress ,
127+ taskArgs . currentImplementation ,
128+ taskArgs . newImplementation ,
129+ taskArgs . verifyContract ,
130+ hre ,
131+ reinitializeArgs ,
132+ ) ;
133+ }
134+
109135task ( "task:upgradeCiphertextCommits" )
110136 . addParam (
111137 "currentImplementation" ,
@@ -127,20 +153,8 @@ task("task:upgradeCiphertextCommits")
127153 true ,
128154 types . boolean ,
129155 )
130- . setAction ( async function (
131- { currentImplementation, newImplementation, useInternalProxyAddress, verifyContract } : TaskArguments ,
132- hre ,
133- ) {
134- await compileImplementations ( currentImplementation , newImplementation , hre ) ;
135-
136- await checkImplementationArtifacts ( "CiphertextCommits" , currentImplementation , newImplementation , hre ) ;
137-
138- if ( useInternalProxyAddress ) {
139- loadGatewayAddresses ( ) ;
140- }
141- const proxyAddress = getRequiredEnvVar ( "CIPHERTEXT_COMMITS_ADDRESS" ) ;
142-
143- await upgradeCurrentToNew ( proxyAddress , currentImplementation , newImplementation , verifyContract , hre ) ;
156+ . setAction ( async function ( taskArgs : TaskArguments , hre ) {
157+ await upgradeContract ( "CiphertextCommits" , "CIPHERTEXT_COMMITS_ADDRESS" , taskArgs , hre ) ;
144158 } ) ;
145159
146160task ( "task:upgradeDecryption" )
@@ -164,20 +178,8 @@ task("task:upgradeDecryption")
164178 true ,
165179 types . boolean ,
166180 )
167- . setAction ( async function (
168- { currentImplementation, newImplementation, useInternalProxyAddress, verifyContract } : TaskArguments ,
169- hre ,
170- ) {
171- await compileImplementations ( currentImplementation , newImplementation , hre ) ;
172-
173- await checkImplementationArtifacts ( "Decryption" , currentImplementation , newImplementation , hre ) ;
174-
175- if ( useInternalProxyAddress ) {
176- loadGatewayAddresses ( ) ;
177- }
178- const proxyAddress = getRequiredEnvVar ( "DECRYPTION_ADDRESS" ) ;
179-
180- await upgradeCurrentToNew ( proxyAddress , currentImplementation , newImplementation , verifyContract , hre ) ;
181+ . setAction ( async function ( taskArgs : TaskArguments , hre ) {
182+ await upgradeContract ( "Decryption" , "DECRYPTION_ADDRESS" , taskArgs , hre ) ;
181183 } ) ;
182184
183185task ( "task:upgradeGatewayConfig" )
@@ -201,24 +203,9 @@ task("task:upgradeGatewayConfig")
201203 true ,
202204 types . boolean ,
203205 )
204- . setAction ( async function (
205- { currentImplementation, newImplementation, useInternalProxyAddress, verifyContract } : TaskArguments ,
206- hre ,
207- ) {
208- await compileImplementations ( currentImplementation , newImplementation , hre ) ;
209-
210- await checkImplementationArtifacts ( "GatewayConfig" , currentImplementation , newImplementation , hre ) ;
211-
212- if ( useInternalProxyAddress ) {
213- loadGatewayAddresses ( ) ;
214- }
215- const proxyAddress = getRequiredEnvVar ( "GATEWAY_CONFIG_ADDRESS" ) ;
216-
206+ . setAction ( async function ( taskArgs : TaskArguments , hre ) {
217207 const kmsContextId = getRequiredEnvVar ( "KMS_CONTEXT_ID" ) ;
218-
219- await upgradeCurrentToNew ( proxyAddress , currentImplementation , newImplementation , verifyContract , hre , [
220- kmsContextId ,
221- ] ) ;
208+ await upgradeContract ( "GatewayConfig" , "GATEWAY_CONFIG_ADDRESS" , taskArgs , hre , [ kmsContextId ] ) ;
222209 } ) ;
223210
224211task ( "task:upgradeKMSGeneration" )
@@ -242,20 +229,8 @@ task("task:upgradeKMSGeneration")
242229 true ,
243230 types . boolean ,
244231 )
245- . setAction ( async function (
246- { currentImplementation, newImplementation, useInternalProxyAddress, verifyContract } : TaskArguments ,
247- hre ,
248- ) {
249- await compileImplementations ( currentImplementation , newImplementation , hre ) ;
250-
251- await checkImplementationArtifacts ( "KMSGeneration" , currentImplementation , newImplementation , hre ) ;
252-
253- if ( useInternalProxyAddress ) {
254- loadGatewayAddresses ( ) ;
255- }
256- const proxyAddress = getRequiredEnvVar ( "KMS_GENERATION_ADDRESS" ) ;
257-
258- await upgradeCurrentToNew ( proxyAddress , currentImplementation , newImplementation , verifyContract , hre ) ;
232+ . setAction ( async function ( taskArgs : TaskArguments , hre ) {
233+ await upgradeContract ( "KMSGeneration" , "KMS_GENERATION_ADDRESS" , taskArgs , hre ) ;
259234 } ) ;
260235
261236task ( "task:upgradeInputVerification" )
@@ -279,18 +254,6 @@ task("task:upgradeInputVerification")
279254 true ,
280255 types . boolean ,
281256 )
282- . setAction ( async function (
283- { currentImplementation, newImplementation, useInternalProxyAddress, verifyContract } : TaskArguments ,
284- hre ,
285- ) {
286- await compileImplementations ( currentImplementation , newImplementation , hre ) ;
287-
288- await checkImplementationArtifacts ( "InputVerification" , currentImplementation , newImplementation , hre ) ;
289-
290- if ( useInternalProxyAddress ) {
291- loadGatewayAddresses ( ) ;
292- }
293- const proxyAddress = getRequiredEnvVar ( "INPUT_VERIFICATION_ADDRESS" ) ;
294-
295- await upgradeCurrentToNew ( proxyAddress , currentImplementation , newImplementation , verifyContract , hre ) ;
257+ . setAction ( async function ( taskArgs : TaskArguments , hre ) {
258+ await upgradeContract ( "InputVerification" , "INPUT_VERIFICATION_ADDRESS" , taskArgs , hre ) ;
296259 } ) ;
0 commit comments