diff --git a/.github/workflows/sharing-smart-contract-test.yml b/.github/workflows/sharing-smart-contract-test.yml index e15403958..19d38d060 100644 --- a/.github/workflows/sharing-smart-contract-test.yml +++ b/.github/workflows/sharing-smart-contract-test.yml @@ -94,6 +94,13 @@ jobs: working-directory: packages/sharing-smart-contract run: npm run test -- --network local-bellecour-fork + - name: Test deployment script + working-directory: packages/sharing-smart-contract + run: | + POCO_ADDRESS=0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f \ + DATASET_REGISTRY_ADDRESS=0x799DAa22654128d0C64d5b79eac9283008158730 \ + npm run deploy -- --network local-bellecour-fork + - name: Set Directory Permissions working-directory: packages/sharing-smart-contract run: sudo chmod -R 777 . diff --git a/packages/sharing-smart-contract/CHANGELOG.md b/packages/sharing-smart-contract/CHANGELOG.md index ee59bd8ba..41507dc96 100644 --- a/packages/sharing-smart-contract/CHANGELOG.md +++ b/packages/sharing-smart-contract/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. ### Changed +- Import Ignition deployment in OZ upgrades plugin (#441) +- Deploy contracts using Hardhat Ignition (#440) - [BREAKING] Remove result proxy url from contract config and deal params (#438). - Fix Sharing contract constructor arguments order (#433) - Update blockscout url diff --git a/packages/sharing-smart-contract/config/config.cjs b/packages/sharing-smart-contract/config/config.cjs index 7f69c1d50..dbeb44c74 100644 --- a/packages/sharing-smart-contract/config/config.cjs +++ b/packages/sharing-smart-contract/config/config.cjs @@ -1,6 +1,8 @@ // Hardhat Ignition does not support ESM modules, so we use CommonJS syntax. // TODO refactor this to use ESM syntax when Hardhat Ignition supports it. +// TODO define addresses by network. + module.exports = { POCO_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f', DATASET_REGISTRY_ADDRESS: '0x799DAa22654128d0C64d5b79eac9283008158730', diff --git a/packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cts b/packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cjs similarity index 98% rename from packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cts rename to packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cjs index 5a05fe1d6..f6de52ecd 100644 --- a/packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cts +++ b/packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cjs @@ -1,3 +1,4 @@ +/* eslint-disable import/extensions */ const { buildModule } = require('@nomicfoundation/hardhat-ignition/modules'); const { diff --git a/packages/sharing-smart-contract/package.json b/packages/sharing-smart-contract/package.json index e5a875c6e..cce7a2ae7 100644 --- a/packages/sharing-smart-contract/package.json +++ b/packages/sharing-smart-contract/package.json @@ -9,7 +9,7 @@ "clean": "hardhat clean", "compile": "hardhat clean && hardhat compile && npm run artifact-to-abis", "verify": "hardhat verify", - "deploy": "hardhat ignition deploy ignition/modules/DataProtectorSharingModule.cts --strategy create2", + "deploy": "hardhat run scripts/deploy.js", "update-env": "hardhat run ./scripts/updateEnv.js", "upgrade": "hardhat run ./scripts/upgrade.js", "upgrade-local-fork": "mkdir -p .openzeppelin/local-fork && cp -r .openzeppelin/prod/. .openzeppelin/local-fork && MANIFEST_DEFAULT_DIR=.openzeppelin/local-fork ENV=prod hardhat run ./scripts/upgrade-local-fork.js", diff --git a/packages/sharing-smart-contract/scripts/deploy.js b/packages/sharing-smart-contract/scripts/deploy.js new file mode 100644 index 000000000..6c92e51db --- /dev/null +++ b/packages/sharing-smart-contract/scripts/deploy.js @@ -0,0 +1,68 @@ +import hre from 'hardhat'; +import { env } from '../config/env.js'; +import DataProtectorSharingModule from '../ignition/modules/DataProtectorSharingModule.cjs'; + +const { ethers, upgrades } = hre; + +/** + * This script deploys DataProtectorSharing contract and its dependencies using + * Hardhat Ignition and createX factory if supported. + * It also imports the deployed contracts into the OpenZeppelin upgrades plugin. + */ + +async function main() { + const pocoAddress = env.POCO_ADDRESS; + const datasetRegistryAddress = env.DATASET_REGISTRY_ADDRESS; + if (!pocoAddress || !datasetRegistryAddress) { + throw new Error('POCO_ADDRESS and DATASET_REGISTRY_ADDRESS are required.'); + } + console.log('Deploying DataProtectorSharingModule...'); + console.log('PoCo address:', pocoAddress); + console.log('DatasetRegistry address:', datasetRegistryAddress); + // Check if the CreateX factory is supported on the current network. + const isCreatexSupported = await isCreatexFactorySupported(); + if (isCreatexSupported) { + console.log('CreateX factory is supported.'); + } else { + console.log('⚠️ CreateX factory is NOT supported.'); + } + // Deploy contracts using Ignition module. + const { addOnlyAppWhitelistRegistry, dataProtectorSharing } = await hre.ignition.deploy( + DataProtectorSharingModule, + { + ...(isCreatexSupported && { + strategy: 'create2', + strategyConfig: hre.userConfig.ignition.strategyConfig.create2, + }), + displayUi: true, // for logs. + }, + ); + // Import proxies in OZ `upgrades` plugin for future upgrades. + console.log(`Importing proxy contracts in OZ upgrades...`); + const whitelistProxyAddress = await addOnlyAppWhitelistRegistry.getAddress(); + await upgrades.forceImport( + whitelistProxyAddress, + await ethers.getContractFactory('AddOnlyAppWhitelistRegistry'), + { + kind: 'transparent', + }, + ); + await upgrades.forceImport( + await dataProtectorSharing.getAddress(), + await ethers.getContractFactory('DataProtectorSharing'), + { + kind: 'transparent', + constructorArgs: [pocoAddress, datasetRegistryAddress, whitelistProxyAddress], + }, + ); +} + +async function isCreatexFactorySupported() { + const code = await ethers.provider.getCode('0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed'); + return code !== '0x'; +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/packages/sharing-smart-contract/tsconfig.json b/packages/sharing-smart-contract/tsconfig.json deleted file mode 100644 index 7793ef8df..000000000 --- a/packages/sharing-smart-contract/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "module": "CommonJS", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true - }, - "include": ["ignition/modules"] -}