Skip to content

Commit 02737b5

Browse files
committed
Import deployments in OZ upgrades
1 parent 85e61c7 commit 02737b5

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

.github/workflows/sharing-smart-contract-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ jobs:
8383
echo "Error: Anvil did not start within the timeout period."
8484
exit 1
8585
86+
- name: Test deployment script
87+
working-directory: packages/sharing-smart-contract
88+
run: npm run deploy -- --network local-bellecour-fork
89+
8690
- name: Upgrade test
8791
working-directory: packages/sharing-smart-contract
8892
run: npm run upgrade-local-fork -- --network local-bellecour-fork

packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cts renamed to packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cjs

File renamed without changes.

packages/sharing-smart-contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"clean": "hardhat clean",
1010
"compile": "hardhat clean && hardhat compile && npm run artifact-to-abis",
1111
"verify": "hardhat verify",
12-
"deploy": "hardhat ignition deploy ignition/modules/DataProtectorSharingModule.cts --strategy create2",
12+
"deploy": "hardhat run scripts/deploy.js",
1313
"update-env": "hardhat run ./scripts/updateEnv.js",
1414
"upgrade": "hardhat run ./scripts/upgrade.js",
1515
"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",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)