From f5d02f9630dc5a192c46f2c6d110b6396c082f05 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 11:46:54 +0100 Subject: [PATCH 01/16] Refactor environment variable handling to use a centralized env module --- .env.template | 20 ++++++++++++++++++++ deploy/deploy.ts | 9 +++++---- env.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ hardhat.config.ts | 16 ++++++++-------- package-lock.json | 12 +++++++++++- package.json | 3 ++- 6 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 .env.template create mode 100644 env.ts diff --git a/.env.template b/.env.template new file mode 100644 index 00000000..8b6a9a9c --- /dev/null +++ b/.env.template @@ -0,0 +1,20 @@ +# Index of the account to be used as the Voucher Manager +# IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... + +# Index of the account to be used as the Voucher Minter +# IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX=... + +# Flag to indicate whether to use a local blockchain fork (set to 'true' for local fork development) +# IS_LOCAL_FORK=... + +# The mnemonic phrase used to derive the wallet's private keys +# MNEMONIC=... + +# The private key for accessing the production account +# PROD_PRIVATE_KEY=... + +# Override the default iExec PoCo (Proof-of-Contribution) contract address +# IEXEC_POCO_ADDRESS=... + +# Indicates whether the deployment involves a factory contract +# FACTORY=... diff --git a/deploy/deploy.ts b/deploy/deploy.ts index 8a4405e0..72a49a68 100644 --- a/deploy/deploy.ts +++ b/deploy/deploy.ts @@ -6,6 +6,7 @@ import { ContractFactory } from 'ethers'; import { deployments, ethers, upgrades } from 'hardhat'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import deploymentConfig from '../config/deployment'; +import { env } from '../env'; import { isLocalFork } from '../hardhat.config'; import * as voucherHubUtils from '../scripts/voucherHubUtils'; import * as voucherUtils from '../scripts/voucherUtils'; @@ -182,15 +183,15 @@ export async function getDeploymentConfig(chainId: number) { // Read default config of the target chain. const config = deploymentConfig[chainId]; // Override config if required. - if (process.env.IEXEC_POCO_ADDRESS) { - config.pocoAddress = process.env.IEXEC_POCO_ADDRESS; + if (env.IEXEC_POCO_ADDRESS) { + config.pocoAddress = env.IEXEC_POCO_ADDRESS; } // Check final config. if (!ethers.isAddress(config.pocoAddress)) { throw new Error('Valid PoCo address must be provided'); } - if (process.env.FACTORY) { - config.factory = process.env.FACTORY == 'true'; + if (env.FACTORY) { + config.factory = env.FACTORY; } return config; } diff --git a/env.ts b/env.ts new file mode 100644 index 00000000..06e3a7c6 --- /dev/null +++ b/env.ts @@ -0,0 +1,42 @@ +import 'dotenv/config'; +import { z } from 'zod'; + +const envSchema = z.object({ + IEXEC_VOUCHER_HUB_ADDRESS: z + .string() + .regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address') + .optional(), + IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX: z + .string() + .optional() + .refine( + (val) => val === undefined || /^\d+$/.test(val), + 'Must be a numeric index if provided', + ), + IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX: z + .string() + .optional() + .refine( + (val) => val === undefined || /^\d+$/.test(val), + 'Must be a numeric index if provided', + ), + IS_LOCAL_FORK: z.preprocess( + (val) => (typeof val === 'string' ? val.toLowerCase() === 'true' : val === true), + z.boolean().default(false), + ), + MNEMONIC: z.string().optional(), + PROD_PRIVATE_KEY: z + .string() + .regex(/^([a-fA-F0-9]{64})$/, 'Invalid private key format') + .optional(), + IEXEC_POCO_ADDRESS: z + .string() + .regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address if provided') + .optional(), + FACTORY: z.preprocess( + (val) => (typeof val === 'string' ? val.toLowerCase() === 'true' : val === true), + z.boolean().default(false), + ), +}); + +export const env = envSchema.parse(process.env); diff --git a/hardhat.config.ts b/hardhat.config.ts index def44235..7942faaf 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -12,11 +12,11 @@ import { defaultLocalhostNetworkParams, } from 'hardhat/internal/core/config/default-config'; import 'solidity-docgen'; +import { env } from './env'; import { forceZeroGasPriceWithSolidityCoverage } from './scripts/utils/modify-solidity-coverage-lib-api-js'; -const managerAccount = Number(process.env.IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX) || null; -const minterAccount = Number(process.env.IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX) || null; -export const isLocalFork = process.env.LOCAL_FORK == 'true'; +const managerAccount = Number(env.IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX) || null; +const minterAccount = Number(env.IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX) || null; const bellecourBlockscoutUrl = 'https://blockscout.bellecour.iex.ec'; const config: HardhatUserConfig = { @@ -50,9 +50,9 @@ const config: HardhatUserConfig = { hardhat: { hardfork: 'berlin', // No EIP-1559 before London fork accounts: { - mnemonic: process.env.MNEMONIC || HARDHAT_NETWORK_MNEMONIC, + mnemonic: env.MNEMONIC || HARDHAT_NETWORK_MNEMONIC, }, - ...(isLocalFork && { + ...(env.IS_LOCAL_FORK && { forking: { url: 'https://bellecour.iex.ec', }, @@ -65,7 +65,7 @@ const config: HardhatUserConfig = { ...defaultHardhatNetworkParams, ...defaultLocalhostNetworkParams, accounts: 'remote', // will use accounts set in hardhat network config - ...(isLocalFork && { + ...(env.IS_LOCAL_FORK && { chainId: 134, }), gasPrice: 0, @@ -74,7 +74,7 @@ const config: HardhatUserConfig = { chainId: 65535, url: 'http://localhost:8545', accounts: { - mnemonic: process.env.MNEMONIC || '', + mnemonic: env.MNEMONIC || '', }, gasPrice: 0, // Get closer to Bellecour network }, @@ -82,7 +82,7 @@ const config: HardhatUserConfig = { chainId: 134, url: 'https://bellecour.iex.ec', accounts: [ - process.env.PROD_PRIVATE_KEY || + env.PROD_PRIVATE_KEY || '0x0000000000000000000000000000000000000000000000000000000000000000', ], gasPrice: 0, diff --git a/package-lock.json b/package-lock.json index 63ca1fe3..8300f610 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "Apache-2.0", "dependencies": { "@iexec/poco": "^5.5.0", - "@openzeppelin/contracts-upgradeable": "^5.0.2" + "@openzeppelin/contracts-upgradeable": "^5.0.2", + "zod": "^3.24.1" }, "devDependencies": { "@amxx/factory": "^1.0.0", @@ -11190,6 +11191,15 @@ "@ethersproject/web": "5.7.1", "@ethersproject/wordlists": "5.7.0" } + }, + "node_modules/zod": { + "version": "3.24.1", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz", + "integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index f565a5c5..c3bfc1b9 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ }, "dependencies": { "@iexec/poco": "^5.5.0", - "@openzeppelin/contracts-upgradeable": "^5.0.2" + "@openzeppelin/contracts-upgradeable": "^5.0.2", + "zod": "^3.24.1" } } From e3dff53ad29d5c855e024c6a0fd6d1ba5a90ffbd Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 11:47:09 +0100 Subject: [PATCH 02/16] Update package dependencies: add dotenv and zod to devDependencies --- package-lock.json | 21 ++++++++++++++++++--- package.json | 7 ++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8300f610..515e4dcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,13 +10,13 @@ "license": "Apache-2.0", "dependencies": { "@iexec/poco": "^5.5.0", - "@openzeppelin/contracts-upgradeable": "^5.0.2", - "zod": "^3.24.1" + "@openzeppelin/contracts-upgradeable": "^5.0.2" }, "devDependencies": { "@amxx/factory": "^1.0.0", "@nomicfoundation/hardhat-toolbox": "^5.0.0", "@openzeppelin/hardhat-upgrades": "^3.2.1", + "dotenv": "^16.4.7", "ethers": "^6.13.2", "hardhat": "^2.22.10", "hardhat-dependency-compiler": "^1.2.1", @@ -27,7 +27,8 @@ "prettier-plugin-organize-imports": "^4.0.0", "prettier-plugin-solidity": "^1.4.1", "sol2uml": "^2.5.19", - "solidity-docgen": "^0.6.0-beta.36" + "solidity-docgen": "^0.6.0-beta.36", + "zod": "^3.24.1" } }, "node_modules/@adraffy/ens-normalize": { @@ -4666,6 +4667,19 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/elliptic": { "version": "6.5.4", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", @@ -11196,6 +11210,7 @@ "version": "3.24.1", "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz", "integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/colinhacks" diff --git a/package.json b/package.json index c3bfc1b9..92a84803 100644 --- a/package.json +++ b/package.json @@ -49,14 +49,15 @@ "prettier-plugin-organize-imports": "^4.0.0", "prettier-plugin-solidity": "^1.4.1", "sol2uml": "^2.5.19", - "solidity-docgen": "^0.6.0-beta.36" + "solidity-docgen": "^0.6.0-beta.36", + "dotenv": "^16.4.7", + "zod": "^3.24.1" }, "devDependencies_comment": { "@sol2uml": "UML generation does not work properly after v2.5.19. Try before bump." }, "dependencies": { "@iexec/poco": "^5.5.0", - "@openzeppelin/contracts-upgradeable": "^5.0.2", - "zod": "^3.24.1" + "@openzeppelin/contracts-upgradeable": "^5.0.2" } } From 80d599d7c49dbae5e6780cdf5ef9ec599f41dc8c Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 12:00:26 +0100 Subject: [PATCH 03/16] Refactor deployment script to use environment variable for local fork check --- deploy/deploy.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deploy/deploy.ts b/deploy/deploy.ts index 72a49a68..15a875dd 100644 --- a/deploy/deploy.ts +++ b/deploy/deploy.ts @@ -7,7 +7,6 @@ import { deployments, ethers, upgrades } from 'hardhat'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import deploymentConfig from '../config/deployment'; import { env } from '../env'; -import { isLocalFork } from '../hardhat.config'; import * as voucherHubUtils from '../scripts/voucherHubUtils'; import * as voucherUtils from '../scripts/voucherUtils'; import { @@ -20,7 +19,7 @@ import { } from '../typechain-types'; export default async function (hre: HardhatRuntimeEnvironment) { - if (isLocalFork) { + if (env.IS_LOCAL_FORK) { /** * This fixes following issue when deploying to a local Bellecour fork: * `ProviderError: No known hardfork for execution on historical block [...] in chain with id 134.` From 8d3de1e06d94f18857b9b93ed36260f35fa626a7 Mon Sep 17 00:00:00 2001 From: Robin Le Caignec <72495599+Le-Caignec@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:44:34 +0700 Subject: [PATCH 04/16] Update .env.template Co-authored-by: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 8b6a9a9c..ece89a0d 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,4 @@ -# Index of the account to be used as the Voucher Manager +# Index of the account generated from the mnemonic to be used as the Voucher Manager # IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... # Index of the account to be used as the Voucher Minter From eb74a711564caa9544929f1cf9dc0588bb823ada Mon Sep 17 00:00:00 2001 From: Robin Le Caignec <72495599+Le-Caignec@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:44:51 +0700 Subject: [PATCH 05/16] Update .env.template Co-authored-by: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index ece89a0d..a926f8fb 100644 --- a/.env.template +++ b/.env.template @@ -1,7 +1,7 @@ # Index of the account generated from the mnemonic to be used as the Voucher Manager # IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... -# Index of the account to be used as the Voucher Minter +# Index of the account generated from the mnemonic to be used as the Voucher Minter # IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX=... # Flag to indicate whether to use a local blockchain fork (set to 'true' for local fork development) From 1400f079eb02c40c78da7e6a3485c9ed7de697e6 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 18:46:41 +0100 Subject: [PATCH 06/16] Update .env.template to reorder variable for better clarity --- .env.template | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.env.template b/.env.template index a926f8fb..cd228a92 100644 --- a/.env.template +++ b/.env.template @@ -1,18 +1,18 @@ +# The mnemonic phrase used to derive the wallet's private keys +# MNEMONIC=... + # Index of the account generated from the mnemonic to be used as the Voucher Manager # IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... # Index of the account generated from the mnemonic to be used as the Voucher Minter # IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX=... -# Flag to indicate whether to use a local blockchain fork (set to 'true' for local fork development) -# IS_LOCAL_FORK=... - -# The mnemonic phrase used to derive the wallet's private keys -# MNEMONIC=... - # The private key for accessing the production account # PROD_PRIVATE_KEY=... +# Flag to indicate whether to use a local blockchain fork (set to 'true' for local fork development) +# IS_LOCAL_FORK=... + # Override the default iExec PoCo (Proof-of-Contribution) contract address # IEXEC_POCO_ADDRESS=... From da33cba228f8080738aa595719ebe9399bf475b4 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 18:55:41 +0100 Subject: [PATCH 07/16] Remove optional validation for IEXEC_VOUCHER_HUB_ADDRESS in env schema --- env.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/env.ts b/env.ts index 06e3a7c6..0b152fc7 100644 --- a/env.ts +++ b/env.ts @@ -2,10 +2,6 @@ import 'dotenv/config'; import { z } from 'zod'; const envSchema = z.object({ - IEXEC_VOUCHER_HUB_ADDRESS: z - .string() - .regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address') - .optional(), IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX: z .string() .optional() From 8eba298cf725bd24354fb3a61f71c6e875420067 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 18:58:31 +0100 Subject: [PATCH 08/16] Refactor environment variable validation to store regex patterns into variables --- env.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/env.ts b/env.ts index 0b152fc7..a494a4d6 100644 --- a/env.ts +++ b/env.ts @@ -1,19 +1,23 @@ import 'dotenv/config'; import { z } from 'zod'; +const addressRegex = /^0x[a-fA-F0-9]{40}$/; +const numericRegex = /^\d+$/; +const privateKeyRegex = /^([a-fA-F0-9]{64})$/; + const envSchema = z.object({ IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX: z .string() .optional() .refine( - (val) => val === undefined || /^\d+$/.test(val), + (val) => val === undefined || numericRegex.test(val), 'Must be a numeric index if provided', ), IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX: z .string() .optional() .refine( - (val) => val === undefined || /^\d+$/.test(val), + (val) => val === undefined || numericRegex.test(val), 'Must be a numeric index if provided', ), IS_LOCAL_FORK: z.preprocess( @@ -21,13 +25,10 @@ const envSchema = z.object({ z.boolean().default(false), ), MNEMONIC: z.string().optional(), - PROD_PRIVATE_KEY: z - .string() - .regex(/^([a-fA-F0-9]{64})$/, 'Invalid private key format') - .optional(), + PROD_PRIVATE_KEY: z.string().regex(privateKeyRegex, 'Invalid private key format').optional(), IEXEC_POCO_ADDRESS: z .string() - .regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address if provided') + .regex(addressRegex, 'Invalid Ethereum address if provided') .optional(), FACTORY: z.preprocess( (val) => (typeof val === 'string' ? val.toLowerCase() === 'true' : val === true), From a5c36dfd39b30243114055a5427e0ceb0560f2c7 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 19:11:58 +0100 Subject: [PATCH 09/16] Refactor environment variable validation to simplify boolean checks --- env.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/env.ts b/env.ts index a494a4d6..9700a4a4 100644 --- a/env.ts +++ b/env.ts @@ -21,7 +21,7 @@ const envSchema = z.object({ 'Must be a numeric index if provided', ), IS_LOCAL_FORK: z.preprocess( - (val) => (typeof val === 'string' ? val.toLowerCase() === 'true' : val === true), + (val) => typeof val === 'string' && val.toLowerCase() === 'true', z.boolean().default(false), ), MNEMONIC: z.string().optional(), @@ -31,7 +31,7 @@ const envSchema = z.object({ .regex(addressRegex, 'Invalid Ethereum address if provided') .optional(), FACTORY: z.preprocess( - (val) => (typeof val === 'string' ? val.toLowerCase() === 'true' : val === true), + (val) => typeof val === 'string' && val.toLowerCase() === 'true', z.boolean().default(false), ), }); From 414deaac308e019f67a98ca2a1f03d5bbb1e5107 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 19:36:10 +0100 Subject: [PATCH 10/16] fix issue --- env.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/env.ts b/env.ts index 9700a4a4..31271c55 100644 --- a/env.ts +++ b/env.ts @@ -8,18 +8,12 @@ const privateKeyRegex = /^([a-fA-F0-9]{64})$/; const envSchema = z.object({ IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX: z .string() - .optional() - .refine( - (val) => val === undefined || numericRegex.test(val), - 'Must be a numeric index if provided', - ), + .refine((val) => numericRegex.test(val), 'Must be a numeric index if provided') + .optional(), IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX: z .string() - .optional() - .refine( - (val) => val === undefined || numericRegex.test(val), - 'Must be a numeric index if provided', - ), + .refine((val) => numericRegex.test(val), 'Must be a numeric index if provided') + .optional(), IS_LOCAL_FORK: z.preprocess( (val) => typeof val === 'string' && val.toLowerCase() === 'true', z.boolean().default(false), From 5fc0fb519d33281ac1582753054a0d23805dcc7f Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 6 Jan 2025 13:17:50 +0100 Subject: [PATCH 11/16] move env.ts file into config folder --- env.ts => config/env.ts | 0 deploy/deploy.ts | 2 +- hardhat.config.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename env.ts => config/env.ts (100%) diff --git a/env.ts b/config/env.ts similarity index 100% rename from env.ts rename to config/env.ts diff --git a/deploy/deploy.ts b/deploy/deploy.ts index 15a875dd..01f7d46f 100644 --- a/deploy/deploy.ts +++ b/deploy/deploy.ts @@ -6,7 +6,7 @@ import { ContractFactory } from 'ethers'; import { deployments, ethers, upgrades } from 'hardhat'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import deploymentConfig from '../config/deployment'; -import { env } from '../env'; +import { env } from '../config/env'; import * as voucherHubUtils from '../scripts/voucherHubUtils'; import * as voucherUtils from '../scripts/voucherUtils'; import { diff --git a/hardhat.config.ts b/hardhat.config.ts index 7942faaf..942efe81 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -12,7 +12,7 @@ import { defaultLocalhostNetworkParams, } from 'hardhat/internal/core/config/default-config'; import 'solidity-docgen'; -import { env } from './env'; +import { env } from './config/env'; import { forceZeroGasPriceWithSolidityCoverage } from './scripts/utils/modify-solidity-coverage-lib-api-js'; const managerAccount = Number(env.IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX) || null; From 8838d4e9c6846e78f51930471b2b3c6f6cb75198 Mon Sep 17 00:00:00 2001 From: Robin Le Caignec <72495599+Le-Caignec@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:54:55 +0700 Subject: [PATCH 12/16] Update .env.template Co-authored-by: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> --- .env.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index cd228a92..43f941cd 100644 --- a/.env.template +++ b/.env.template @@ -1,8 +1,8 @@ # The mnemonic phrase used to derive the wallet's private keys -# MNEMONIC=... +MNEMONIC=... # Index of the account generated from the mnemonic to be used as the Voucher Manager -# IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... +IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... # Index of the account generated from the mnemonic to be used as the Voucher Minter # IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX=... From b485bf1b30716b8ae65deacae809c1d11987755d Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 6 Jan 2025 13:55:39 +0100 Subject: [PATCH 13/16] Update .env.template to uncomment configuration variables --- .env.template | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index 43f941cd..34fd49c7 100644 --- a/.env.template +++ b/.env.template @@ -5,16 +5,16 @@ MNEMONIC=... IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX=... # Index of the account generated from the mnemonic to be used as the Voucher Minter -# IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX=... +IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX=... # The private key for accessing the production account -# PROD_PRIVATE_KEY=... +PROD_PRIVATE_KEY=... # Flag to indicate whether to use a local blockchain fork (set to 'true' for local fork development) -# IS_LOCAL_FORK=... +IS_LOCAL_FORK=... # Override the default iExec PoCo (Proof-of-Contribution) contract address -# IEXEC_POCO_ADDRESS=... +IEXEC_POCO_ADDRESS=... # Indicates whether the deployment involves a factory contract -# FACTORY=... +FACTORY=... From 8d7e13629e1d73f0e506b935165fd59c79cb1f21 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 6 Jan 2025 14:03:11 +0100 Subject: [PATCH 14/16] Rename FACTORY environment variable to USE_FACTORY for clarity and update related references --- .env.template | 2 +- config/env.ts | 2 +- deploy/deploy.ts | 4 ++-- package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index 34fd49c7..1177d0e4 100644 --- a/.env.template +++ b/.env.template @@ -17,4 +17,4 @@ IS_LOCAL_FORK=... IEXEC_POCO_ADDRESS=... # Indicates whether the deployment involves a factory contract -FACTORY=... +USE_FACTORY=... diff --git a/config/env.ts b/config/env.ts index 31271c55..ae34b008 100644 --- a/config/env.ts +++ b/config/env.ts @@ -24,7 +24,7 @@ const envSchema = z.object({ .string() .regex(addressRegex, 'Invalid Ethereum address if provided') .optional(), - FACTORY: z.preprocess( + USE_FACTORY: z.preprocess( (val) => typeof val === 'string' && val.toLowerCase() === 'true', z.boolean().default(false), ), diff --git a/deploy/deploy.ts b/deploy/deploy.ts index 01f7d46f..fa6dc55d 100644 --- a/deploy/deploy.ts +++ b/deploy/deploy.ts @@ -189,8 +189,8 @@ export async function getDeploymentConfig(chainId: number) { if (!ethers.isAddress(config.pocoAddress)) { throw new Error('Valid PoCo address must be provided'); } - if (env.FACTORY) { - config.factory = env.FACTORY; + if (env.USE_FACTORY) { + config.factory = env.USE_FACTORY; } return config; } diff --git a/package.json b/package.json index 92a84803..0954303f 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "prepare": "husky", "build": "npx hardhat compile", "test": "npx hardhat test", - "test-ci": "npm run test && FACTORY=false npm run test", + "test-ci": "npm run test && USE_FACTORY=false npm run test", "coverage": "npx hardhat coverage", "format": "npx prettier --write", "doc": "npx hardhat docgen", From 30568aa8e3b9192d4e4bc826270d22a0fd2915df Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 6 Jan 2025 14:25:30 +0100 Subject: [PATCH 15/16] Refactor environment variable handling to transform string indices to numbers --- config/env.ts | 2 ++ hardhat.config.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config/env.ts b/config/env.ts index ae34b008..079ffe81 100644 --- a/config/env.ts +++ b/config/env.ts @@ -9,10 +9,12 @@ const envSchema = z.object({ IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX: z .string() .refine((val) => numericRegex.test(val), 'Must be a numeric index if provided') + .transform((val) => Number(val)) .optional(), IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX: z .string() .refine((val) => numericRegex.test(val), 'Must be a numeric index if provided') + .transform((val) => Number(val)) .optional(), IS_LOCAL_FORK: z.preprocess( (val) => typeof val === 'string' && val.toLowerCase() === 'true', diff --git a/hardhat.config.ts b/hardhat.config.ts index 942efe81..57bf9fc5 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -15,8 +15,8 @@ import 'solidity-docgen'; import { env } from './config/env'; import { forceZeroGasPriceWithSolidityCoverage } from './scripts/utils/modify-solidity-coverage-lib-api-js'; -const managerAccount = Number(env.IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX) || null; -const minterAccount = Number(env.IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX) || null; +const managerAccount = env.IEXEC_VOUCHER_MANAGER_ACCOUNT_INDEX || null; +const minterAccount = env.IEXEC_VOUCHER_MINTER_ACCOUNT_INDEX || null; const bellecourBlockscoutUrl = 'https://blockscout.bellecour.iex.ec'; const config: HardhatUserConfig = { From 40fc9b2d56548d78a60fe90ec9ad35e6f3f0a9ee Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 6 Jan 2025 15:00:06 +0100 Subject: [PATCH 16/16] Update CHANGELOG.md --- CHANGELOG.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b579f03f..d514765e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,23 @@ # Changelog ## vNEXT + +- Better handling for env variables. (#55) - Remove references to blockscout v5. (#49) - Verify VoucherProxy contracts. (#51) ## v1.0.0 ### What's new? + - Allow users to access resources of the iExec network via a sponsorship voucher. ### More details + - Upgrade Solidity Compiler to `v0.8.27`. (#45) - Bump dependencies: (#44) - - `@openzeppelin/hardhat-upgrades`, `hardhat`, `ethers`, `prettier`, and others [minor version bump] - - `prettier-plugin-organize-imports@4` + - `@openzeppelin/hardhat-upgrades`, `hardhat`, `ethers`, `prettier`, and others [minor version bump] + - `prettier-plugin-organize-imports@4` - Add `getVoucherProxyCodeHash(..)` & `isRefundedTask(..)` view functions. (#43) - Add `predictVoucher(..)` & `isVoucher(..)` functions. (#42) - Generate UML class diagram for contracts. (#41) @@ -44,12 +48,12 @@ - Match orders through voucher. (#12) - Add external-hardhat network configuration. (#11) - Add voucher credit and SRLC manipulation. (#10) - - SRLC and iExec poco is mocked. - - set voucher credit as VoucherHub is ERC20. + - SRLC and iExec poco is mocked. + - set voucher credit as VoucherHub is ERC20. - Upgrade configuration: (#9) - - Upgrade dependencies: hardhat, husky, iExec Poco. - - Ignore mocks in coverage. - - Add solidity optimizer and use Bellecour network config. + - Upgrade dependencies: hardhat, husky, iExec Poco. + - Ignore mocks in coverage. + - Add solidity optimizer and use Bellecour network config. - Add role-based access control to VoucherHub. (#8) - Create voucher from VoucherHub with : type, expiration, authorize list. (#6) - Create vouchers with create2. (#5)