-
Notifications
You must be signed in to change notification settings - Fork 179
refactor deployment scripts #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,47 @@ | ||
| import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; | ||
| import hre from "hardhat"; | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { getSavedRepo, getDeployedAddresses, getContractAddress, log } from "../../../scripts/constants"; | ||
|
|
||
| module.exports = buildModule("UpdateRegistryHubV2", (m) => { | ||
| const repo = hre.network.config.chainId === 42220 ? "prod" : "staging"; | ||
| const deployedAddressesPath = path.join(__dirname, `../../deployments/${repo}/deployed_addresses.json`); | ||
| const chainId = hre.network.config.chainId; | ||
| const networkName = hre.network.name; | ||
|
|
||
| console.log(`Reading deployed addresses from: ${deployedAddressesPath}`); | ||
| const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8")); | ||
| log.info(`Network: ${networkName}, Chain ID: ${chainId}`); | ||
|
|
||
| const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"]; | ||
| const registryIdCardAddress = deployedAddresses["DeployIdCardRegistryModule#IdentityRegistryIdCard"]; | ||
| const hubAddress = deployedAddresses["DeployHubV2#IdentityVerificationHub"]; | ||
| const repoName = getSavedRepo(networkName); | ||
| const deployedAddresses = getDeployedAddresses(repoName); | ||
|
|
||
| // Validate addresses | ||
| if (!registryAddress) { | ||
| throw new Error("IdentityRegistry address not found in deployed addresses"); | ||
| } | ||
| if (!registryIdCardAddress) { | ||
| throw new Error("IdentityRegistryIdCard address not found in deployed addresses"); | ||
| } | ||
| if (!hubAddress) { | ||
| throw new Error("IdentityVerificationHub address not found in deployed addresses"); | ||
| } | ||
| log.info(`Using repo: ${repoName}`); | ||
|
|
||
| console.log(`Registry address: ${registryAddress}`); | ||
| console.log(`Registry ID Card address: ${registryIdCardAddress}`); | ||
| console.log(`Hub address: ${hubAddress}`); | ||
| try { | ||
| const registryAddress = getContractAddress("DeployRegistryModule#IdentityRegistry", deployedAddresses); | ||
| const registryIdCardAddress = getContractAddress("DeployIdCardRegistryModule#IdentityRegistryIdCard", deployedAddresses); | ||
| const hubAddress = getContractAddress("DeployHubV2#IdentityVerificationHub", deployedAddresses); | ||
|
|
||
| const deployedRegistryInstance = m.contractAt("IdentityRegistryImplV1", registryAddress); | ||
| const deployedRegistryIdCardInstance = m.contractAt("IdentityRegistryIdCardImplV1", registryIdCardAddress); | ||
| log.info(`Registry address: ${registryAddress}`); | ||
| log.info(`Registry ID Card address: ${registryIdCardAddress}`); | ||
| log.info(`Hub address: ${hubAddress}`); | ||
|
|
||
| console.log("✓ Created registry contract instances"); | ||
| const deployedRegistryInstance = m.contractAt("IdentityRegistryImplV1", registryAddress); | ||
| const deployedRegistryIdCardInstance = m.contractAt("IdentityRegistryIdCardImplV1", registryIdCardAddress); | ||
|
|
||
| log.success("Created registry contract instances"); | ||
|
|
||
| // Execute the updateHub calls | ||
| console.log("Updating hub address on IdentityRegistry..."); | ||
| m.call(deployedRegistryInstance, "updateHub", [hubAddress]); | ||
| log.step("Updating hub address on IdentityRegistry..."); | ||
| m.call(deployedRegistryInstance, "updateHub", [hubAddress]); | ||
|
|
||
| console.log("Updating hub address on IdentityRegistryIdCard..."); | ||
| m.call(deployedRegistryIdCardInstance, "updateHub", [hubAddress]); | ||
| log.step("Updating hub address on IdentityRegistryIdCard..."); | ||
| m.call(deployedRegistryIdCardInstance, "updateHub", [hubAddress]); | ||
|
|
||
| console.log("✓ Hub update calls initiated successfully"); | ||
| log.success("Hub update calls initiated successfully"); | ||
|
|
||
| return { | ||
| deployedRegistryInstance, | ||
| deployedRegistryIdCardInstance | ||
| }; | ||
| deployedRegistryInstance, | ||
| deployedRegistryIdCardInstance | ||
| }; | ||
| } catch (error) { | ||
| log.error(`Failed to update registry hub: ${error}`); | ||
| throw error; | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| how to deploy and update the protocol | ||
|
|
||
| Main contracts: | ||
| - Hub | ||
| - Registries | ||
| - Passports | ||
| - ID cards | ||
|
|
||
| Hub and Registries are following an upgradeable proxy pattern. | ||
| Use only the Proxy address for everything. | ||
|
|
||
| Secondary contracts: | ||
| - vc_and_disclose verifiers | ||
| - vc_and_disclose_id verifiers | ||
| - register verifiers' | ||
| - register id verifiers | ||
| - dsc verifiers | ||
|
|
||
| How to update the protocol: | ||
|
|
||
|
|
||
| ### Deploy the Hub V2 and the Identity registry | ||
|
|
||
| ``` | ||
| yarn deploy:hub:v2 | ||
| ``` | ||
|
|
||
| ``` | ||
| deploy:registry:idcard | ||
| ``` | ||
|
|
||
| ### Set the registries address in the hub | ||
|
|
||
| ```` | ||
| yarn set:hub:v2 | ||
| ```` | ||
|
|
||
| Set the verifiers in the hub | ||
|
|
||
| ``` | ||
| yarn set:verifiers:v2 | ||
| ``` | ||
|
|
||
| ### Update the registries | ||
|
|
||
| ```` | ||
| yarn set:registry:hub:v2 | ||
| ``` |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import * as path from "path"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import * as fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const ATTESTATION_ID = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| E_PASSPORT: '0x0000000000000000000000000000000000000000000000000000000000000001', | ||||||||||||||||||||||||||||||||||||||||||||||||
| EU_ID_CARD: '0x0000000000000000000000000000000000000000000000000000000000000002', | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const ATTESTATION_TO_REGISTRY = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| E_PASSPORT: 'DeployRegistryModule#IdentityRegistry', | ||||||||||||||||||||||||||||||||||||||||||||||||
| EU_ID_CARD: 'DeployIdCardRegistryModule#IdentityRegistryIdCard', | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const NETWORK_TO_CHAIN_ID: Record<string, string> = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| localhost: '31337', | ||||||||||||||||||||||||||||||||||||||||||||||||
| hardhat: '31337', | ||||||||||||||||||||||||||||||||||||||||||||||||
| alfajores: '44787', | ||||||||||||||||||||||||||||||||||||||||||||||||
| celoAlfajores: '44787', | ||||||||||||||||||||||||||||||||||||||||||||||||
| celo: '42220', | ||||||||||||||||||||||||||||||||||||||||||||||||
| mainnet: '42220', | ||||||||||||||||||||||||||||||||||||||||||||||||
| staging: '44787', | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const CHAIN_ID_TO_SAVED_REPO: Record<string, string> = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| '42220' : 'prod', | ||||||||||||||||||||||||||||||||||||||||||||||||
| '44787' : 'staging' | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const getChainId = (network: string): string => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const chainId = NETWORK_TO_CHAIN_ID[network]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`Network '${network}' mapped to Chain ID: ${chainId}`); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return chainId; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const getSavedRepo = (network: string): string => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| return repoName; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation and formatting issues. Line 36 has incorrect indentation and the function is missing proper spacing. Apply this fix: export const getSavedRepo = (network: string): string => {
-const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]];
-return repoName;
+ const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]];
+ return repoName;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const getDeployedAddresses = (repoName: string): any => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const addresses_path = path.join(__dirname, `../ignition/deployments/${repoName}/deployed_addresses.json`); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return JSON.parse(fs.readFileSync(addresses_path, "utf-8")); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| export const getContractAbi = (repoName: string, deploymentArtifactName: string): any => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const abi_path = path.join(__dirname, `../ignition/deployments/${repoName}/artifacts/${deploymentArtifactName}.json`); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return JSON.parse(fs.readFileSync(abi_path, "utf-8")).abi; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for file operations. The Consider adding try-catch blocks or checking file existence: export const getDeployedAddresses = (repoName: string): any => {
const addresses_path = path.join(__dirname, `../ignition/deployments/${repoName}/deployed_addresses.json`);
+ if (!fs.existsSync(addresses_path)) {
+ throw new Error(`Deployed addresses file not found: ${addresses_path}`);
+ }
return JSON.parse(fs.readFileSync(addresses_path, "utf-8"));
}
+
export const getContractAbi = (repoName: string, deploymentArtifactName: string): any => {
const abi_path = path.join(__dirname, `../ignition/deployments/${repoName}/artifacts/${deploymentArtifactName}.json`);
+ if (!fs.existsSync(abi_path)) {
+ throw new Error(`Contract ABI file not found: ${abi_path}`);
+ }
return JSON.parse(fs.readFileSync(abi_path, "utf-8")).abi;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export function getContractAddress(exactName: string, deployedAddresses : any): any { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (exactName in deployedAddresses) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return deployedAddresses[exactName]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| throw Error(`No contract address found for ${exactName}`) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Console colors | ||||||||||||||||||||||||||||||||||||||||||||||||
| const colors = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| reset: '\x1b[0m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| red: '\x1b[31m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| green: '\x1b[32m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| yellow: '\x1b[33m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| blue: '\x1b[34m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| magenta: '\x1b[35m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| cyan: '\x1b[36m', | ||||||||||||||||||||||||||||||||||||||||||||||||
| white: '\x1b[37m' | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const log = { | ||||||||||||||||||||||||||||||||||||||||||||||||
| info: (msg: string) => console.log(`${colors.blue}[INFO]${colors.reset} ${msg}`), | ||||||||||||||||||||||||||||||||||||||||||||||||
| success: (msg: string) => console.log(`${colors.green}[SUCCESS]${colors.reset} ${msg}`), | ||||||||||||||||||||||||||||||||||||||||||||||||
| warning: (msg: string) => console.log(`${colors.yellow}[WARNING]${colors.reset} ${msg}`), | ||||||||||||||||||||||||||||||||||||||||||||||||
| error: (msg: string) => console.log(`${colors.red}[ERROR]${colors.reset} ${msg}`), | ||||||||||||||||||||||||||||||||||||||||||||||||
| step: (msg: string) => console.log(`${colors.magenta}[STEP]${colors.reset} ${msg}`) | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix missing semicolon after object declaration.
The ATTESTATION_TO_REGISTRY object is missing a semicolon on line 12, which could lead to potential ASI (Automatic Semicolon Insertion) issues.
Apply this fix:
export const ATTESTATION_TO_REGISTRY = { E_PASSPORT: 'DeployRegistryModule#IdentityRegistry', EU_ID_CARD: 'DeployIdCardRegistryModule#IdentityRegistryIdCard', -} +};📝 Committable suggestion
🤖 Prompt for AI Agents