Skip to content

Commit b4a5d2a

Browse files
authored
refactor(gateway-contracts): get reinitialize args from env variables
1 parent 9b3b91e commit b4a5d2a

1 file changed

Lines changed: 26 additions & 127 deletions

File tree

gateway-contracts/tasks/upgradeContracts.ts

Lines changed: 26 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function upgradeCurrentToNew(
2525
newImplementation: string,
2626
verifyContract: boolean,
2727
hre: HardhatRuntimeEnvironment,
28-
reinitializeArgs?: unknown[],
28+
reinitializeArgs: unknown[] = [],
2929
) {
3030
const deployerPrivateKey = getRequiredEnvVar("DEPLOYER_PRIVATE_KEY");
3131
const deployer = new Wallet(deployerPrivateKey).connect(hre.ethers.provider);
@@ -116,12 +116,6 @@ task("task:upgradeMultichainAcl")
116116
"newImplementation",
117117
"The new implementation solidity contract path and name, eg: contracts/examples/MultichainAclUpgradedExample.sol:MultichainAclUpgradedExample",
118118
)
119-
.addOptionalParam(
120-
"reinitializeArgs",
121-
`The reinitialize arguments for the new implementation, a list in JSON format, eg: '[ "arg1", { "arg2Field1": "arg2Value1" }, [{ "arg3Field1": "arg3Value1"}] ]'`,
122-
[],
123-
types.json,
124-
)
125119
.addOptionalParam(
126120
"useInternalProxyAddress",
127121
"If proxy address from the /addresses directory should be used",
@@ -135,13 +129,7 @@ task("task:upgradeMultichainAcl")
135129
types.boolean,
136130
)
137131
.setAction(async function (
138-
{
139-
currentImplementation,
140-
newImplementation,
141-
reinitializeArgs,
142-
useInternalProxyAddress,
143-
verifyContract,
144-
}: TaskArguments,
132+
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
145133
hre,
146134
) {
147135
await compileImplementations(currentImplementation, newImplementation, hre);
@@ -156,14 +144,7 @@ task("task:upgradeMultichainAcl")
156144
proxyAddress = getRequiredEnvVar("MULTICHAIN_ACL_ADDRESS");
157145
}
158146

159-
await upgradeCurrentToNew(
160-
proxyAddress,
161-
currentImplementation,
162-
newImplementation,
163-
verifyContract,
164-
hre,
165-
reinitializeArgs,
166-
);
147+
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
167148
});
168149

169150
task("task:upgradeCiphertextCommits")
@@ -175,12 +156,6 @@ task("task:upgradeCiphertextCommits")
175156
"newImplementation",
176157
"The new implementation solidity contract path and name, eg: contracts/examples/CiphertextCommitsUpgradedExample.sol:CiphertextCommitsUpgradedExample",
177158
)
178-
.addOptionalParam(
179-
"reinitializeArgs",
180-
`The reinitialize arguments for the new implementation, a list in JSON format, eg: '[ "arg1", { "arg2Field1": "arg2Value1" }, [{ "arg3Field1": "arg3Value1"}] ]'`,
181-
[],
182-
types.json,
183-
)
184159
.addOptionalParam(
185160
"useInternalProxyAddress",
186161
"If proxy address from the /addresses directory should be used",
@@ -194,13 +169,7 @@ task("task:upgradeCiphertextCommits")
194169
types.boolean,
195170
)
196171
.setAction(async function (
197-
{
198-
currentImplementation,
199-
newImplementation,
200-
reinitializeArgs,
201-
useInternalProxyAddress,
202-
verifyContract,
203-
}: TaskArguments,
172+
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
204173
hre,
205174
) {
206175
await compileImplementations(currentImplementation, newImplementation, hre);
@@ -215,14 +184,7 @@ task("task:upgradeCiphertextCommits")
215184
proxyAddress = getRequiredEnvVar("CIPHERTEXT_COMMITS_ADDRESS");
216185
}
217186

218-
await upgradeCurrentToNew(
219-
proxyAddress,
220-
currentImplementation,
221-
newImplementation,
222-
verifyContract,
223-
hre,
224-
reinitializeArgs,
225-
);
187+
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
226188
});
227189

228190
task("task:upgradeDecryption")
@@ -234,12 +196,6 @@ task("task:upgradeDecryption")
234196
"newImplementation",
235197
"The new implementation solidity contract path and name, eg: contracts/examples/DecryptionUpgradedExample.sol:DecryptionUpgradedExample",
236198
)
237-
.addOptionalParam(
238-
"reinitializeArgs",
239-
`The reinitialize arguments for the new implementation, a list in JSON format, eg: '[ "arg1", { "arg2Field1": "arg2Value1" }, [{ "arg3Field1": "arg3Value1"}] ]'`,
240-
[],
241-
types.json,
242-
)
243199
.addOptionalParam(
244200
"useInternalProxyAddress",
245201
"If proxy address from the /addresses directory should be used",
@@ -253,13 +209,7 @@ task("task:upgradeDecryption")
253209
types.boolean,
254210
)
255211
.setAction(async function (
256-
{
257-
currentImplementation,
258-
newImplementation,
259-
reinitializeArgs,
260-
useInternalProxyAddress,
261-
verifyContract,
262-
}: TaskArguments,
212+
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
263213
hre,
264214
) {
265215
await compileImplementations(currentImplementation, newImplementation, hre);
@@ -274,14 +224,7 @@ task("task:upgradeDecryption")
274224
proxyAddress = getRequiredEnvVar("DECRYPTION_ADDRESS");
275225
}
276226

277-
await upgradeCurrentToNew(
278-
proxyAddress,
279-
currentImplementation,
280-
newImplementation,
281-
verifyContract,
282-
hre,
283-
reinitializeArgs,
284-
);
227+
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
285228
});
286229

287230
task("task:upgradeGatewayConfig")
@@ -293,12 +236,6 @@ task("task:upgradeGatewayConfig")
293236
"newImplementation",
294237
"The new implementation solidity contract path and name, eg: contracts/examples/GatewayConfigUpgradedExample.sol:GatewayConfigUpgradedExample",
295238
)
296-
.addOptionalParam(
297-
"reinitializeArgs",
298-
`The reinitialize arguments for the new implementation, a list in JSON format, eg: '[ "arg1", { "arg2Field1": "arg2Value1" }, [{ "arg3Field1": "arg3Value1"}] ]'`,
299-
[],
300-
types.json,
301-
)
302239
.addOptionalParam(
303240
"useInternalProxyAddress",
304241
"If proxy address from the /addresses directory should be used",
@@ -312,13 +249,7 @@ task("task:upgradeGatewayConfig")
312249
types.boolean,
313250
)
314251
.setAction(async function (
315-
{
316-
currentImplementation,
317-
newImplementation,
318-
reinitializeArgs,
319-
useInternalProxyAddress,
320-
verifyContract,
321-
}: TaskArguments,
252+
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
322253
hre,
323254
) {
324255
await compileImplementations(currentImplementation, newImplementation, hre);
@@ -333,14 +264,20 @@ task("task:upgradeGatewayConfig")
333264
proxyAddress = getRequiredEnvVar("GATEWAY_CONFIG_ADDRESS");
334265
}
335266

336-
await upgradeCurrentToNew(
337-
proxyAddress,
338-
currentImplementation,
339-
newImplementation,
340-
verifyContract,
341-
hre,
342-
reinitializeArgs,
343-
);
267+
// Get custodians from environment variables
268+
const numCustodians = parseInt(getRequiredEnvVar("NUM_CUSTODIANS"));
269+
const custodians = [];
270+
for (let idx = 0; idx < numCustodians; idx++) {
271+
custodians.push({
272+
txSenderAddress: getRequiredEnvVar(`CUSTODIAN_TX_SENDER_ADDRESS_${idx}`),
273+
signerAddress: getRequiredEnvVar(`CUSTODIAN_SIGNER_ADDRESS_${idx}`),
274+
encryptionKey: getRequiredEnvVar(`CUSTODIAN_ENCRYPTION_KEY_${idx}`),
275+
});
276+
}
277+
278+
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre, [
279+
custodians,
280+
]);
344281
});
345282

346283
task("task:upgradeKmsManagement")
@@ -352,12 +289,6 @@ task("task:upgradeKmsManagement")
352289
"newImplementation",
353290
"The new implementation solidity contract path and name, eg: contracts/examples/KmsManagementUpgradedExample.sol:KmsManagementUpgradedExample",
354291
)
355-
.addOptionalParam(
356-
"reinitializeArgs",
357-
`The reinitialize arguments for the new implementation, a list in JSON format, eg: '[ "arg1", { "arg2Field1": "arg2Value1" }, [{ "arg3Field1": "arg3Value1"}] ]'`,
358-
[],
359-
types.json,
360-
)
361292
.addOptionalParam(
362293
"useInternalProxyAddress",
363294
"If proxy address from the /addresses directory should be used",
@@ -371,13 +302,7 @@ task("task:upgradeKmsManagement")
371302
types.boolean,
372303
)
373304
.setAction(async function (
374-
{
375-
currentImplementation,
376-
newImplementation,
377-
reinitializeArgs,
378-
useInternalProxyAddress,
379-
verifyContract,
380-
}: TaskArguments,
305+
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
381306
hre,
382307
) {
383308
await compileImplementations(currentImplementation, newImplementation, hre);
@@ -392,14 +317,7 @@ task("task:upgradeKmsManagement")
392317
proxyAddress = getRequiredEnvVar("KMS_MANAGEMENT_ADDRESS");
393318
}
394319

395-
await upgradeCurrentToNew(
396-
proxyAddress,
397-
currentImplementation,
398-
newImplementation,
399-
verifyContract,
400-
hre,
401-
reinitializeArgs,
402-
);
320+
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
403321
});
404322

405323
task("task:upgradeInputVerification")
@@ -411,12 +329,6 @@ task("task:upgradeInputVerification")
411329
"newImplementation",
412330
"The new implementation solidity contract path and name, eg: contracts/examples/InputVerificationUpgradedExample.sol:InputVerificationUpgradedExample",
413331
)
414-
.addOptionalParam(
415-
"reinitializeArgs",
416-
`The reinitialize arguments for the new implementation, a list in JSON format, eg: '[ "arg1", { "arg2Field1": "arg2Value1" }, [{ "arg3Field1": "arg3Value1"}] ]'`,
417-
[],
418-
types.json,
419-
)
420332
.addOptionalParam(
421333
"useInternalProxyAddress",
422334
"If proxy address from the /addresses directory should be used",
@@ -430,13 +342,7 @@ task("task:upgradeInputVerification")
430342
types.boolean,
431343
)
432344
.setAction(async function (
433-
{
434-
currentImplementation,
435-
newImplementation,
436-
reinitializeArgs,
437-
useInternalProxyAddress,
438-
verifyContract,
439-
}: TaskArguments,
345+
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
440346
hre,
441347
) {
442348
await compileImplementations(currentImplementation, newImplementation, hre);
@@ -451,12 +357,5 @@ task("task:upgradeInputVerification")
451357
proxyAddress = getRequiredEnvVar("INPUT_VERIFICATION_ADDRESS");
452358
}
453359

454-
await upgradeCurrentToNew(
455-
proxyAddress,
456-
currentImplementation,
457-
newImplementation,
458-
verifyContract,
459-
hre,
460-
reinitializeArgs,
461-
);
360+
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre);
462361
});

0 commit comments

Comments
 (0)