Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 30 additions & 33 deletions contracts/ignition/modules/scripts/updateRegistryHubV2.ts
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;
}
});
2 changes: 1 addition & 1 deletion contracts/ignition/modules/verifiers/deployAllVerifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from "path";

const deployVerifiers = {
vcAndDiscloseVerifier: false,
vcAndDiscloseIdVerifier: true,
vcAndDiscloseIdVerifier: false,
registerIdVerifier: false,
registerVerifier: false,
dscVerifier: false,
Expand Down
48 changes: 48 additions & 0 deletions contracts/ignition/readme.md
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
```
75 changes: 75 additions & 0 deletions contracts/scripts/constants.ts
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',
}

Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const ATTESTATION_TO_REGISTRY = {
E_PASSPORT: 'DeployRegistryModule#IdentityRegistry',
EU_ID_CARD: 'DeployIdCardRegistryModule#IdentityRegistryIdCard',
}
export const ATTESTATION_TO_REGISTRY = {
E_PASSPORT: 'DeployRegistryModule#IdentityRegistry',
EU_ID_CARD: 'DeployIdCardRegistryModule#IdentityRegistryIdCard',
};
🤖 Prompt for AI Agents
In contracts/scripts/constants.ts around lines 9 to 13, the
ATTESTATION_TO_REGISTRY object declaration is missing a semicolon at the end.
Add a semicolon after the closing brace of the object to prevent potential
Automatic Semicolon Insertion issues.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const getSavedRepo = (network: string): string => {
const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]];
return repoName;
};
export const getSavedRepo = (network: string): string => {
const repoName = CHAIN_ID_TO_SAVED_REPO[NETWORK_TO_CHAIN_ID[network]];
return repoName;
};
🤖 Prompt for AI Agents
In contracts/scripts/constants.ts around lines 35 to 39, the function
getSavedRepo has incorrect indentation and lacks proper spacing. Adjust the
indentation of the function body to be consistently indented inside the function
block, and ensure there is a blank line after the function declaration for
better readability.


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for file operations.

The getDeployedAddresses and getContractAbi functions read files synchronously without error handling. If the files don't exist or are malformed, the application will crash with an unhelpful error.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
}
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;
}
🤖 Prompt for AI Agents
In contracts/scripts/constants.ts around lines 41 to 48, the functions
getDeployedAddresses and getContractAbi read files synchronously without error
handling, which can cause crashes if files are missing or malformed. Wrap the
file reading and JSON parsing logic in try-catch blocks to catch and handle
errors gracefully. Optionally, check if the file exists before reading it to
provide clearer error messages or fallback behavior.


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}`)
};
Loading