Skip to content

Commit ed0f3da

Browse files
committed
refactor(common): align missed tasks
1 parent 322725a commit ed0f3da

File tree

6 files changed

+59
-72
lines changed

6 files changed

+59
-72
lines changed

gateway-contracts/tasks/getters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { task, types } from "hardhat/config";
2-
import type { TaskArguments } from "hardhat/types";
2+
import type { HardhatEthersHelpers, TaskArguments } from "hardhat/types";
33

44
import { GatewayConfig } from "../typechain-types";
55

66
import { getRequiredEnvVar, loadGatewayAddresses } from "./utils";
77

88
async function loadGatewayConfigContract(
99
useInternalProxyAddress: boolean,
10-
ethers: typeof import("hardhat").ethers,
10+
ethers: HardhatEthersHelpers,
1111
): Promise<GatewayConfig> {
1212
if (useInternalProxyAddress) {
1313
loadGatewayAddresses();

gateway-contracts/tasks/reshareKeys.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import dotenv from "dotenv";
21
import { task, types } from "hardhat/config";
3-
import path from "path";
42

5-
import { ADDRESSES_DIR } from "../hardhat.config";
6-
import { getRequiredEnvVar } from "./utils/loadVariables";
3+
import { getRequiredEnvVar, loadGatewayAddresses } from "./utils/loadVariables";
74

85
task("task:prssInit")
96
.addParam(
@@ -20,7 +17,7 @@ task("task:prssInit")
2017
const deployer = new hre.ethers.Wallet(deployerPrivateKey).connect(hre.ethers.provider);
2118

2219
if (useInternalProxyAddress) {
23-
dotenv.config({ path: path.join(ADDRESSES_DIR, ".env.gateway"), override: true });
20+
loadGatewayAddresses();
2421
}
2522
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");
2623

@@ -46,7 +43,7 @@ task("task:keyReshareSameSet")
4643
const deployer = new hre.ethers.Wallet(deployerPrivateKey).connect(hre.ethers.provider);
4744

4845
if (useInternalProxyAddress) {
49-
dotenv.config({ path: path.join(ADDRESSES_DIR, ".env.gateway"), override: true });
46+
loadGatewayAddresses();
5047
}
5148
const proxyAddress = getRequiredEnvVar("KMS_GENERATION_ADDRESS");
5249

host-contracts/tasks/taskUtils.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import dotenv from 'dotenv';
2-
import fs from 'fs';
3-
import { task } from 'hardhat/config';
4-
import type { TaskArguments } from 'hardhat/types';
1+
import { task, types } from 'hardhat/config';
52

63
import { InputVerifier, KMSVerifier } from '../types';
4+
import { getRequiredEnvVar, loadHostAddresses } from './utils/loadVariables';
75

86
////////////////////////////////////////////////////////////////////////////////
97
// Faucet
@@ -27,18 +25,18 @@ task('task:faucetToPrivate')
2725
////////////////////////////////////////////////////////////////////////////////
2826

2927
task('task:getKmsSigners')
30-
.addOptionalParam(
31-
'customKmsVerifierAddress',
32-
'Use a custom address for the KMSVerifier contract instead of the default one - ie stored inside .env.host',
28+
.addParam(
29+
'useInternalProxyAddress',
30+
'If proxy address from the /addresses directory should be used',
31+
false,
32+
types.boolean,
3333
)
34-
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
34+
.setAction(async function ({ useInternalProxyAddress }, { ethers }) {
3535
const factory = await ethers.getContractFactory('./contracts/KMSVerifier.sol:KMSVerifier');
36-
let kmsAdd;
37-
if (taskArguments.customKmsVerifierAddress) {
38-
kmsAdd = taskArguments.customKmsVerifierAddress;
39-
} else {
40-
kmsAdd = dotenv.parse(fs.readFileSync('addresses/.env.host')).KMS_VERIFIER_CONTRACT_ADDRESS;
36+
if (useInternalProxyAddress) {
37+
loadHostAddresses();
4138
}
39+
const kmsAdd = getRequiredEnvVar('KMS_VERIFIER_CONTRACT_ADDRESS');
4240
const kmsVerifier = factory.attach(kmsAdd).connect(ethers.provider) as KMSVerifier;
4341
const listCurrentKMSSigners = await kmsVerifier.getKmsSigners();
4442
console.log('The list of current KMS Signers stored inside KMSVerifier contract is: ', listCurrentKMSSigners);
@@ -49,18 +47,18 @@ task('task:getKmsSigners')
4947
////////////////////////////////////////////////////////////////////////////////
5048

5149
task('task:getCoprocessorSigners')
52-
.addOptionalParam(
53-
'customInputVerifierAddress',
54-
'Use a custom address for the InputVerifier contract instead of the default one - ie stored inside .env.host',
50+
.addParam(
51+
'useInternalProxyAddress',
52+
'If proxy address from the /addresses directory should be used',
53+
false,
54+
types.boolean,
5555
)
56-
.setAction(async function (taskArguments: TaskArguments, { ethers }) {
56+
.setAction(async function ({ useInternalProxyAddress }, { ethers }) {
5757
const factory = await ethers.getContractFactory('./contracts/InputVerifier.sol:InputVerifier');
58-
let inputVerifierAdd;
59-
if (taskArguments.customInputVerifierAddress) {
60-
inputVerifierAdd = taskArguments.customInputVerifierAddress;
61-
} else {
62-
inputVerifierAdd = dotenv.parse(fs.readFileSync('addresses/.env.host')).INPUT_VERIFIER_CONTRACT_ADDRESS;
58+
if (useInternalProxyAddress) {
59+
loadHostAddresses();
6360
}
61+
const inputVerifierAdd = getRequiredEnvVar('INPUT_VERIFIER_CONTRACT_ADDRESS');
6462
const inputVerifier = factory.attach(inputVerifierAdd).connect(ethers.provider) as InputVerifier;
6563
const listCurrentCoprocessorSigners = await inputVerifier.getCoprocessorSigners();
6664
console.log(

host-contracts/tasks/upgradeContracts.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -355,28 +355,19 @@ task('task:upgradeInputVerifier')
355355
true,
356356
types.boolean,
357357
)
358-
.setAction(async function (
359-
{ currentImplementation, newImplementation, useInternalProxyAddress, verifyContract }: TaskArguments,
360-
hre,
361-
) {
362-
await compileImplementations(currentImplementation, newImplementation, hre);
363-
await checkImplementationArtifacts('InputVerifier', currentImplementation, newImplementation, hre);
364-
365-
if (useInternalProxyAddress) {
358+
.setAction(async function (taskArgs: TaskArguments, hre) {
359+
if (taskArgs.useInternalProxyAddress) {
366360
loadHostAddresses();
367361
}
368-
const proxyAddress = getRequiredEnvVar('INPUT_VERIFIER_CONTRACT_ADDRESS');
369362

370-
let initialSigners: string[] = [];
363+
const initialSigners: string[] = [];
371364
const numSigners = getRequiredEnvVar('NUM_COPROCESSORS');
372365
for (let idx = 0; idx < +numSigners; idx++) {
373-
const inputSignerAddress = getRequiredEnvVar(`COPROCESSOR_SIGNER_ADDRESS_${idx}`);
374-
initialSigners.push(inputSignerAddress);
366+
initialSigners.push(getRequiredEnvVar(`COPROCESSOR_SIGNER_ADDRESS_${idx}`));
375367
}
376-
377368
const coprocessorThreshold = getRequiredEnvVar('COPROCESSOR_THRESHOLD');
378369

379-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre, [
370+
await upgradeContract('InputVerifier', 'INPUT_VERIFIER_CONTRACT_ADDRESS', taskArgs, hre, [
380371
initialSigners,
381372
coprocessorThreshold,
382373
]);
@@ -421,29 +412,10 @@ task('task:upgradeHCULimit')
421412
'20000000',
422413
types.string,
423414
)
424-
.setAction(async function (
425-
{
426-
currentImplementation,
427-
newImplementation,
428-
useInternalProxyAddress,
429-
verifyContract,
430-
hcuCapPerBlock,
431-
maxHcuDepthPerTx,
432-
maxHcuPerTx,
433-
}: TaskArguments,
434-
hre,
435-
) {
436-
await compileImplementations(currentImplementation, newImplementation, hre);
437-
await checkImplementationArtifacts('HCULimit', currentImplementation, newImplementation, hre);
438-
439-
if (useInternalProxyAddress) {
440-
loadHostAddresses();
441-
}
442-
const proxyAddress = getRequiredEnvVar('HCU_LIMIT_CONTRACT_ADDRESS');
443-
444-
await upgradeCurrentToNew(proxyAddress, currentImplementation, newImplementation, verifyContract, hre, [
445-
BigInt(hcuCapPerBlock),
446-
BigInt(maxHcuDepthPerTx),
447-
BigInt(maxHcuPerTx),
415+
.setAction(async function (taskArgs: TaskArguments, hre) {
416+
await upgradeContract('HCULimit', 'HCU_LIMIT_CONTRACT_ADDRESS', taskArgs, hre, [
417+
BigInt(taskArgs.hcuCapPerBlock),
418+
BigInt(taskArgs.maxHcuDepthPerTx),
419+
BigInt(taskArgs.maxHcuPerTx),
448420
]);
449421
});

library-solidity/tasks/addPausers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import dotenv from 'dotenv';
21
import { task, types } from 'hardhat/config';
3-
import path from 'path';
42

5-
import { getRequiredEnvVar } from './utils/loadVariables';
3+
import { getRequiredEnvVar, loadHostAddresses } from './utils/loadVariables';
64

75
// Add pausers to the PauserSet contract
86
// Note: Internal PauserSet address is defined in the `addresses/` directory. It should be used
@@ -24,7 +22,7 @@ task('task:addHostPausers')
2422
}
2523

2624
if (useInternalProxyAddress) {
27-
dotenv.config({ path: path.join('fhevmTemp/addresses/', '.env.host'), override: true });
25+
loadHostAddresses();
2826
}
2927
const pauserSetAddress = getRequiredEnvVar('PAUSER_SET_CONTRACT_ADDRESS');
3028

library-solidity/tasks/utils/loadVariables.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import dotenv from 'dotenv';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const ADDRESSES_DIR = path.resolve(__dirname, '../../fhevmTemp/addresses');
6+
const HOST_ADDRESSES_ENV_FILE_NAME = '.env.host';
7+
18
// Get the required environment variable, throw an error if it's not set
29
// We only check if the variable is set, not if it's empty
310
export function getRequiredEnvVar(name: string): string {
@@ -6,3 +13,18 @@ export function getRequiredEnvVar(name: string): string {
613
}
714
return process.env[name]!;
815
}
16+
17+
// Load the addresses as environment variables from the env file
18+
export function loadAddressEnvVarsFromFile(fileName: string) {
19+
const envFilePath = path.join(ADDRESSES_DIR, fileName);
20+
21+
if (!fs.existsSync(envFilePath)) {
22+
throw new Error(`Environment file for addresses not found: ${envFilePath}`);
23+
}
24+
25+
dotenv.config({ path: envFilePath, override: true });
26+
}
27+
28+
export function loadHostAddresses() {
29+
loadAddressEnvVarsFromFile(HOST_ADDRESSES_ENV_FILE_NAME);
30+
}

0 commit comments

Comments
 (0)