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