|
| 1 | +import hre from 'hardhat'; |
| 2 | +import { env } from '../config/env.js'; |
| 3 | +import DataProtectorSharingModule from '../ignition/modules/DataProtectorSharingModule.cjs'; |
| 4 | + |
| 5 | +const { ethers, upgrades } = hre; |
| 6 | + |
| 7 | +/** |
| 8 | + * This script deploys DataProtectorSharing contract and its dependencies using |
| 9 | + * Hardhat Ignition and createX factory if supported. |
| 10 | + * It also imports the deployed contracts into the OpenZeppelin upgrades plugin. |
| 11 | + */ |
| 12 | + |
| 13 | +async function main() { |
| 14 | + const pocoAddress = env.POCO_ADDRESS; |
| 15 | + const datasetRegistryAddress = env.DATASET_REGISTRY_ADDRESS; |
| 16 | + if (!pocoAddress || !datasetRegistryAddress) { |
| 17 | + throw new Error('POCO_ADDRESS and DATASET_REGISTRY_ADDRESS are required.'); |
| 18 | + } |
| 19 | + console.log('Deploying DataProtectorSharingModule...'); |
| 20 | + console.log('PoCo address:', pocoAddress); |
| 21 | + console.log('DatasetRegistry address:', datasetRegistryAddress); |
| 22 | + // Check if the CreateX factory is supported on the current network. |
| 23 | + const isCreatexSupported = await isCreatexFactorySupported(); |
| 24 | + if (isCreatexSupported) { |
| 25 | + console.log('CreateX factory is supported.'); |
| 26 | + } else { |
| 27 | + console.log('⚠️ CreateX factory is NOT supported.'); |
| 28 | + } |
| 29 | + // Deploy contracts using Ignition module. |
| 30 | + const { addOnlyAppWhitelistRegistry, dataProtectorSharing } = await hre.ignition.deploy( |
| 31 | + DataProtectorSharingModule, |
| 32 | + { |
| 33 | + ...(isCreatexSupported && { |
| 34 | + strategy: 'create2', |
| 35 | + strategyConfig: hre.userConfig.ignition.strategyConfig.create2, |
| 36 | + }), |
| 37 | + displayUi: true, // for logs. |
| 38 | + }, |
| 39 | + ); |
| 40 | + // Import proxies in OZ `upgrades` plugin for future upgrades. |
| 41 | + console.log(`Importing proxy contracts in OZ upgrades...`); |
| 42 | + const whitelistProxyAddress = await addOnlyAppWhitelistRegistry.getAddress(); |
| 43 | + await upgrades.forceImport( |
| 44 | + whitelistProxyAddress, |
| 45 | + await ethers.getContractFactory('AddOnlyAppWhitelistRegistry'), |
| 46 | + { |
| 47 | + kind: 'transparent', |
| 48 | + }, |
| 49 | + ); |
| 50 | + await upgrades.forceImport( |
| 51 | + await dataProtectorSharing.getAddress(), |
| 52 | + await ethers.getContractFactory('DataProtectorSharing'), |
| 53 | + { |
| 54 | + kind: 'transparent', |
| 55 | + constructorArgs: [pocoAddress, datasetRegistryAddress, whitelistProxyAddress], |
| 56 | + }, |
| 57 | + ); |
| 58 | +} |
| 59 | + |
| 60 | +async function isCreatexFactorySupported() { |
| 61 | + const code = await ethers.provider.getCode('0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed'); |
| 62 | + return code !== '0x'; |
| 63 | +} |
| 64 | + |
| 65 | +main().catch((error) => { |
| 66 | + console.error(error); |
| 67 | + process.exitCode = 1; |
| 68 | +}); |
0 commit comments