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
3 changes: 3 additions & 0 deletions examples/CRISP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"ciphernode:add": "pnpm -C packages/crisp-contracts ciphernode:add",
"ciphernode:mint:tokens": "pnpm -C packages/crisp-contracts ciphernode:mint:tokens",
"ciphernode:add:self": "pnpm -C packages/crisp-contracts ciphernode:add:self",
"deploy:contracts:full:mock": "pnpm -C packages/crisp-contracts deploy:contracts:full:mock",
"deploy:contracts:mock": "pnpm -C packages/crisp-contracts deploy:contracts:mock",
"deploy:contracts": "pnpm -C packages/crisp-contracts deploy:contracts",
"test": "pnpm test:e2e",
"test:circuits:inputs": "node --test test/governanceCircuit.test.ts",
"test:circuits": "cd circuits && nargo test",
Expand Down
1 change: 0 additions & 1 deletion examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "@enclave-e3/contracts/scripts";
import { Enclave__factory as EnclaveFactory } from "@enclave-e3/contracts/types";

import { execSync } from "child_process";
import hre from "hardhat";

const IMAGE_ID =
Expand Down
24 changes: 23 additions & 1 deletion examples/CRISP/packages/crisp-contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@
// This file is provided WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
import { deployEnclave } from "@enclave-e3/contracts/scripts";
import { deployEnclave, updateE3Config } from "@enclave-e3/contracts/scripts";
import { deployCRISPContracts } from "./crisp";
import path from "path";

import hre from "hardhat";
import { fileURLToPath } from "url";

// Map contract names to config keys
const contractMapping: Record<string, string> = {
CRISPProgram: "e3_program",
Enclave: "enclave",
CiphernodeRegistryOwnable: "ciphernode_registry",
BondingRegistry: "bonding_registry",
MockUSDC: "fee_token",
};

// Get __dirname equivalent in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
* Deploys the Enclave and CRISP contracts
*/
export const deploy = async () => {
const chain = hre.globalOptions.network;
Comment thread
ctrlc03 marked this conversation as resolved.

const shouldDeployEnclave = Boolean(process.env.DEPLOY_ENCLAVE) ?? false;

if (shouldDeployEnclave) {
await deployEnclave(true);
}
await deployCRISPContracts();

// this expects you to run it from CRISP's root
updateE3Config(chain, path.join(__dirname, "..", "..", "..", "enclave.config.yaml"), contractMapping);
}

deploy().catch((err => {
Expand Down
4 changes: 2 additions & 2 deletions examples/CRISP/packages/crisp-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"solady": "^0.1.13"
},
"devDependencies": {
"@crisp-e3/sdk": "workspace:^",
"@crisp-e3/zk-inputs": "workspace:^",
"@nomicfoundation/hardhat-ethers": "4",
"@nomicfoundation/hardhat-ethers-chai-matchers": "^3.0.0",
"@nomicfoundation/hardhat-network-helpers": "3",
Expand All @@ -60,8 +62,6 @@
"@types/mocha": ">=9.1.0",
"@types/node": "^22.18.0",
"chai": "^6.2.0",
"@crisp-e3/sdk": "workspace:^",
"@crisp-e3/zk-inputs": "workspace:^",
"dotenv": "^16.4.5",
"ethers": "^6.15.0",
"forge-std": "github:foundry-rs/forge-std#v1.9.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/enclave-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@types/chai": "^4.3.20",
"@types/chai-as-promised": "^8.0.2",
"@types/fs-extra": "^11.0.4",
"@types/js-yaml": "^4.0.9",
"@types/mocha": "^10.0.10",
"@types/node": "^22.18.0",
"@typescript-eslint/eslint-plugin": "^7.11.0",
Expand Down Expand Up @@ -173,6 +174,7 @@
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@zk-kit/lean-imt.sol": "2.0.1",
"js-yaml": "^4.1.1",
"poseidon-solidity": "0.0.5"
},
"packageManager": "pnpm@10.7.1+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808"
Expand Down
88 changes: 88 additions & 0 deletions packages/enclave-contracts/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
import fs from "fs";
import yaml from "js-yaml";
import path from "path";

export const deploymentsFile = path.join("deployed_contracts.json");
Expand All @@ -26,6 +27,26 @@ export interface Deployments {
[chainName: string]: ChainDeployments;
}

/**
* Defines the Enclave.config.yaml structure
*/
export interface EnclaveConfig {
chains: Array<{
name: string;
rpc_url: string;
contracts: {
e3_program?: { address: string; deploy_block: number };
enclave?: { address: string; deploy_block: number };
ciphernode_registry?: { address: string; deploy_block: number };
bonding_registry?: { address: string; deploy_block: number };
fee_token?: { address: string; deploy_block: number };
};
}>;
// we don't care about the below fields
program: unknown;
nodes: unknown;
}

/**
* Store the deployment arguments for a given contract and chain
* @param args - The deployment arguments to store
Expand Down Expand Up @@ -140,3 +161,70 @@ export function areArraysEqual<T>(arr1: T[], arr2: T[]): boolean {

return true;
}

/**
* The function to update the enclave.config.yaml file with the deployed contract addresses
* @param chainToConfig - The chain name to update in the config
* @param pathToConfigFile - The path to the enclave.config.yaml file
* @param contractMapping - A mapping of contract names to config keys
*/
Comment thread
ctrlc03 marked this conversation as resolved.
export const updateE3Config = (
chainToConfig: string,
pathToConfigFile: string,
contractMapping: Record<string, string>,
rpcUrl?: string,
): void => {
const fileContent = fs.readFileSync(pathToConfigFile, "utf8");
const config = yaml.load(fileContent) as EnclaveConfig;

// Find the hardhat chain config
// Find the chain config or create it
let configChain = config.chains.find((chain) => chain.name === chainToConfig);

if (!configChain) {
console.log(
`Chain "${chainToConfig}" not found in config. Creating new entry...`,
);

if (!rpcUrl) {
console.warn(
"Warning: No RPC URL provided. You'll need to update it manually in the config.",
);
}

configChain = {
name: chainToConfig,
rpc_url: rpcUrl || `ws://localhost:8545`,
contracts: {},
};

config.chains.push(configChain);
console.log(`✓ Created new chain entry for "${chainToConfig}"`);
}

console.log(`\nUpdating contracts for chain: ${chainToConfig}`);

// Update contract addresses and deploy blocks
for (const [contractName, configKey] of Object.entries(contractMapping)) {
const deployment = readDeploymentArgs(contractName, chainToConfig);

if (deployment) {
configChain.contracts[configKey as keyof typeof configChain.contracts] = {
Comment thread
ctrlc03 marked this conversation as resolved.
address: deployment.address,
deploy_block: deployment.blockNumber ?? 1,
Comment thread
ctrlc03 marked this conversation as resolved.
};
console.log(
`✓ Updated ${configKey}: ${deployment.address} (block ${deployment.blockNumber ?? 1})`,
);
}
}

// Write updated config back to file
const yamlStr = yaml.dump(config, {
indent: 2,
lineWidth: -1, // Don't wrap lines
});

fs.writeFileSync(pathToConfigFile, yamlStr + "\n", "utf8");
console.log("\n✓ enclave.config.yaml updated successfully!");
};
Comment thread
ctrlc03 marked this conversation as resolved.
26 changes: 16 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading